locked
Memory leak !DumpHeap shows 'Free' RRS feed

  • Question

  •  

    I am trying to trace what appears to be a memory leak in our .NET application. I seems to only manifest itself in our production environment so I am using WinDbg to see if I can shed any more light on the problem. I have a question. If I do !DumpHeap -stat at the end I see the heap by type. At the end I see:

     

    00000642788de2e8     9059      7773688 System.Byte[]
    00000642788d6af0    53180     11712768 System.Object[]
    0000000000174e80       96     20745080      Free

    What is the type listed as 'Free'? It seems to be the largest contributor to the heap size. If it is indeed 'Free' then why is it showing up on the heap? I have tried something like:

     

    .foreach (obj {!dumpheap -type System.Byte[] -short}) {.echo obj;!gcroot -nostacks obj}

    to see if any of the "roots" look familiar but first there is alot of output and it is hard to tell which is a "real" root and which will go away soon.

     

    I have been looking in the !FinalizeQueue listing and mainly been concentrating my efforts there. It seems particularly with DataSets if they are not expicitly 'Dispose'd they immediatly go to the finalize queue which is not collected very ofter.

     

    I have also tried to use the CLRProfiler in a development environement but this seems to completely lock up the machine. I don't think this tool was meant for an application as larger as ours.

     

    Any other tips for tracking a managed memory leak down?

     

     

    Thank you.

     

    Kevin

    Sunday, October 21, 2007 9:54 PM

Answers

  • Hi Kevin,

    “Free” means that the memory can be used now and it’s referenced by nothing.

    There are several references on this issue:

    ·         .NET Memory Leak Case Study: The Event Handlers That Made The Memory Baloon

    ·         Tracking down managed memory leaks (how to find a GC leak)

    ·         Identify And Prevent Memory Leaks In Managed Code

    And alternative memory profiler:

    ·         ANTS Profiler™ - .NET code and memory profiler

    ·         .NET Memory Profiler 3.0

    Hope this helps!

    Thanks!

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Tuesday, October 23, 2007 6:02 AM
  • Hi Kevin,

    This free memory area was reserved for the further use of your application. And the CLR’s managed heap is not the unmanaged heap, it is managed by CLR itself.

    Thanks!

    Wednesday, October 24, 2007 3:47 AM

All replies

  • Hi Kevin,

    “Free” means that the memory can be used now and it’s referenced by nothing.

    There are several references on this issue:

    ·         .NET Memory Leak Case Study: The Event Handlers That Made The Memory Baloon

    ·         Tracking down managed memory leaks (how to find a GC leak)

    ·         Identify And Prevent Memory Leaks In Managed Code

    And alternative memory profiler:

    ·         ANTS Profiler™ - .NET code and memory profiler

    ·         .NET Memory Profiler 3.0

    Hope this helps!

    Thanks!

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Tuesday, October 23, 2007 6:02 AM
  • Thank you for the links. I will look through these

     

    That would bewhat I would assume to be the meaning of 'Free' . My question is why does it still show up on the heap? When does 'Free' memory not show up on my process' heap? The way I understood it was that if it wasn't referenced anymore then it would be returned to the global memory heap so that it is available for other processes to allocate.

     

    Thanks again.

     

    Kevin

    Wednesday, October 24, 2007 1:38 AM
  • Hi Kevin,

    This free memory area was reserved for the further use of your application. And the CLR’s managed heap is not the unmanaged heap, it is managed by CLR itself.

    Thanks!

    Wednesday, October 24, 2007 3:47 AM