ASP.NET Memory Leak

Posted on 2012-09-22
Last Modified: 2012-09-24
We've got an IIS memory leak on Windows Server 2008 R2 64-bit.

The memory usage climbs steadily to 3 GB.

I've used the ANTS memory profiler to see what is happening and have a lot of memory held by _TimerCallback where  System.Threading.TimerCallback calls System.Web.Caching.CacheExpires.

We're not aware of any specific caching code in the app, so this seems to be something IIS is doing.

Can anyone suggest what the cause might be?
Question by:purplesoup
    LVL 16

    Assisted Solution

    The most memory usage mostly come from data or files. Check if you have any code that receives huge resources and put it in cache and stuff. Or maybe opening a file  and not closing it?

    Author Comment

    Thanks for your comment.

    The thing is - this is a huge app - I need to have something more specific to look for - in particular I don't understand why the main classes left in memory appear to have come from this callback to System.Web.Caching.CacheExpires - particularly as I say there is no specific caching code in the app itself, so it look as if this is something IIS is doing.
    LVL 60

    Assisted Solution

    May not be necessary be caching but can be objects created with each timercallback taken as argument. Memory leak is common when there is loop around creation of objects and making it even more complex when the argument to the new object has callback based variable...just quick thoughts

    Sometimes there is also static instance  involved in such creation that can be slowly leaking the memory. Best practice is used static method where possible. Here is one article for info
    LVL 51

    Assisted Solution

    IIS is actually a very simple application.  All IIS does is either respond with static pages (HTML) or relay page requests to server side code.

    Leaks are always due to the server side code.  It will take time but you'll have to find an object that has not released memory correctly.

    Author Comment

    Well the only code I could fine with timercallback was log4net - I can try turning it off. Anyone know how to do that? This is what I found and is what I'm going to try:

    How do I completely disable all logging at runtime?

    Setting the Threshold on the Hierarchy to Level OFF will disable all logging from that Hierarchy. This can be done in the log4net configuration file by setting the "threshold" attribute on the log4net configuration element to "OFF". For example:

    <log4net threshold="OFF" />
    LVL 16

    Assisted Solution

    by:Kamal Khaleefa
    are you using virtual machine ?

    if yes virtual always consumes memory

    try to make sure that you are closing all the connections with the database

    and try to comment the threading and try again
    LVL 60

    Accepted Solution

    Actually I am thinking of even disabling the event handler method for all timecallback, maybe simply with another objection within that function and see if the "leaks" still exist. Just trying to be make sure we are "barking on the right tree".

    I do not recommend logging to be disable where possible as this is security requirement, the key is how to offload this instead of having the code to perform it. of course if we are saying debugging log, that should be well coded with debug option set off and release build to eliminate all this.

    One challenge I have in the past is the stage of optimisation which removed codes that inadvertently introduced and remove codes that missed logs and orphan codes. Have exception handler checks as well as they can introduce "leak" indirectly

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    I was supporting a handful of Windows 2008 (non-R2) 2 node clusters with shared quorum disks. Some had SQL 2008 installed and some were just a vendor application that we supported. For the purposes of this article it doesn’t really matter which so w…
    This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
    This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now