Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET app using lots of memory - Leak?

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.

like image 483
webnoob Avatar asked Jan 23 '23 12:01

webnoob


1 Answers

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.

like image 130
Coxy Avatar answered Jan 26 '23 11:01

Coxy