none
Memory Leak with a Partial CLR Callstack RRS feed

  • Question

  • Hello, We have a memory leak.

    After enabling user mode stack trace database in GFlags we know for cetrain that the following callstack shows the allocations that cause the leak:

    address 10576ef8 found in
    _HEAP @ 1250000
      HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
        10576ed0 000a 0000  [03]   10576ef8    0000c - (busy)
        mscoreei!CLRRuntimeInfoImpl::`vftable'
        7c94b244 ntdll!RtlAllocateHeapSlowly+0x00000044
        7c919c0c ntdll!RtlAllocateHeap+0x00000e64
        603b14a4 mscoreei!UtilExecutionEngine::ClrHeapAlloc+0x00000014
        603b14cb mscoreei!ClrHeapAlloc+0x00000023
        603b14f7 mscoreei!ClrAllocInProcessHeapBootstrap+0x0000002e
        603b1614 mscoreei!operator new[]+0x0000002b
        603d402b +0x0000005f
        603d5142 mscoreei!GetThunkUseState+0x00000025
        603d6fe8 mscoreei!_CorDllMain+0x00000056
        79015012 mscoree!ShellShim__CorDllMain+0x000000ad
        7c90118a ntdll!LdrpCallInitRoutine+0x00000014
        7c919a6d ntdll!LdrpInitializeThread+0x000000c0
        7c9198e6 ntdll!_LdrpInitialize+0x00000219
        7c90e457 ntdll!KiUserApcDispatcher+0x00000007

    Looks like thread initialization but if anyone can tell more about this callstack it may help us.

    Saturday, April 7, 2012 11:54 AM

Answers

  • I just finished re-reading all your postings.  I thought you were running out of memory and getting an error when the memory ran out which would eventually will happen with any memory leak.  I think the calls stack that gets killed immediately is this type error.  Your call stack contains many things including interupts and calls inside the dll which aren't part of your C# application.

    One cause of the memroy leak may be coming from an object you are passing into the dlls in the parameter list that isn't being released by you program.  Another reason could be a "NEW" statement in your code that doesn't require a "NEW".


    jdweng

    Monday, April 9, 2012 9:47 AM

All replies

  • The memory leak is coming from the Allocate function.  A memory leak wth the allocate function is caused by a process requesting memory and then never releasing the used memory.  Allocate is used by a lot of different process to request from the windows operating system memory.  The error you are getting only tells you that "one" of the processes requested memory using the allocate function and there was no memory available.  It doesn't tell you which process wasn't releasing the memory like it should.

    There are two methods for fincing problems like this

    1)  Systemmaticaly eliminate prgrams/function until you find the source of the problem

    2)  Create a table of allocates and de-allocates with the process that is requesting each alocation and see which processes aren't releasing the memory.


    jdweng

    Saturday, April 7, 2012 1:41 PM
  • Thanks for the reply.

    Just to clarify: I don't see any error. The callstack is indeed a callstack of an allocation and I know that this specific kind of allocation never gets freed through some analysis that I've done using Windbg !heap commands. I can explain more but I believe that once we know that this callstack is the cause for the leak, the details of the analysis are not important.

    This is a thread initialization call stack and I can put a break point at any point in this call stack, yet even when the break point hits, it doesn't help much as I can't find what triggers this from our code or from 3rd party dll's that we use.

    One last note, our base code is C# but we use unmanaged dll's and finally, I know that the thread that is initialized in the callstack above (and gets killed immediatly) is an unmanaged thread.

    Sunday, April 8, 2012 6:05 PM
  • The call stack isn't going to give you any clues in fixing your problem.  The allocated memory is shared by many processes including your program.  One of the other processes is requesting memory and can't get the memory because your program has used too much memory.

    You have to figure out why your program is using all the memory or figure out how to release the memory when you are finished with the memory.


    jdweng

    Sunday, April 8, 2012 8:54 PM
  • Can you elaborate a bit more as to how you see that one of the processes is requesting memory and can't get it?
    Monday, April 9, 2012 7:32 AM
  • I just finished re-reading all your postings.  I thought you were running out of memory and getting an error when the memory ran out which would eventually will happen with any memory leak.  I think the calls stack that gets killed immediately is this type error.  Your call stack contains many things including interupts and calls inside the dll which aren't part of your C# application.

    One cause of the memroy leak may be coming from an object you are passing into the dlls in the parameter list that isn't being released by you program.  Another reason could be a "NEW" statement in your code that doesn't require a "NEW".


    jdweng

    Monday, April 9, 2012 9:47 AM