views:

289

answers:

3

Hi All,

I have an ASP.NET website that seems to be using a lot of memory. I left it for 7 hours on Sunday and it reached 3.2gb. I thought .NET handled all it's own garbage collection / free'd objects and so on, so I am not really sure where to start looking for a solution.

The website uses XML's heavily so I thought this could be the issue but I have implemented the global use of the XMLSerializer to try and rule this out.

I also have a custom handler that deals with all the images, resizes, caches and then loads from cache where it can. Could this be causing any issues?

Sorry to be so vague but the problem is that I don't know where to start with the issue really. Any help appreciated.

Server info: .NET 2.0 Windows 2008 server IIS7

Thanks in advance.

+1  A: 

When dealing with the file system its really important that you dispose your readers and temporary objects.

Carl Bergquist
Could you clarify this for me please? I thought if I create an object, .NET free's it automatically?
webnoob
+3  A: 

Best place to start is using a profiler. RedGate has the ANTS Memory Profiler which is really good and has a free trial. Product page here.

You run the application, attach the profiler then start using the page as normal. The profiler collects information about the objects in use and this should allow you to pinpoint the root cause of the problem.

Once in my application, it turned out to be that we were accidentally creating a NHibernate SessionFactory for every single query that we performed. These were all referenced internally by NHibernate, which meant that they were never freed in addition to being horribly slow and inefficient. The profiler lead us right to it and we never would have found it otherwise.

Coxy
Downloading now. Thanks.
webnoob
Ok, I have the app running and profiling my site. Can you give me a heads up on what I should be looking out for? I noticed each time I do a snapshot, the String memory usage is about 15% higher each time in the summary panel.
webnoob
@webnoob - I'm afraid I don't have it running at the moment, but there should be an 'expandable tree' view that you can drill down and see exactly what is creating/holding onto the bulk of all the new objects each time.
Coxy
+1  A: 

An alternative to RedGate is using adplus and WinDbg. Also read this blog:

http://blogs.msdn.com/tess/

This is an excellent source of help with debugging issues.

My SysAdmin and I had successfully used adplus and WinDbg to find a memory leak in an ASP.NET Application. My developers mistake was, that they accidentally used ASP.NET's cache without an expiration timeout.

Another Bug was, that a developer used Attribute overloads with XMLSerialization. With that feature .net will allays create a new serializer helper (whatever) assembly. Assemblies cannot be unloaded, so the application eats a lot of memory

Arthur
I think I have addressed the XML issues in my app. I am calling the contstrucor with a type and also creating a global instance of the serialization object for each of my XML's, so this should sort it. If that is not what you meant, can you please clarify? Will look into the adplus and windbg
webnoob
I'm talking about this (http://msdn.microsoft.com/en-us/library/bfaxz1a0(VS.80).aspx) constructor. If you'r using this (http://msdn.microsoft.com/en-us/library/71s92ee1(VS.80).aspx) constructor you should not have the troubles we had.
Arthur
Ah ok, in that case I have this dealt with. Thanks.
webnoob