none
How to find memory leaks ? RRS feed

  • Question

  • In my program i do a memory observation with 'OpenNETCF.WindowsCE.MemoryManagement.MemoryLoad'

    I can see that the value of 'MemoryLoad' is growing to 99% (within two days)

    The article 'Finding Managed Memory leaks using the .Net CF Remote Performance Monitor' is saying:

    The best way to track the amount of memory used to store objects in the GC heap is to monitor the "Managed Bytes in use After GC" counter in RPM.  Graphing the value of this counter over time using Perfmon is the easiest way to determine whether the heap is continually growing.

    So i started NetCFRPM/perform and watched on Managed Bytes in use After GC / Process Heap - but they are constant.

    What other i can observe (my managed application uses an unmanaged dll using also event/delegate mechanism) ?

    Tuesday, October 12, 2010 10:43 AM

All replies

  • That's good information.  Remember that your managed code is not running in a vacuum; underneath is Windows CE and not every object allocated is a managed object.  Think about window handles, bitmaps, etc., etc.  My guess is that you are either 1) P/Invoking some native call that allocates memory and you are not freeing it, or 2) you are using some managed object that requires you to call Close() or Dispose() to free unmanaged resources and you are not doing that.

    Paul T.

    Tuesday, October 12, 2010 2:44 PM
  • Yes i know that there are also unmanaged objects :-)

    It is possible to observe the unmanaged memory with NetCFRPM/perform ?

    I will cut down my code to see what piece let growing the memory (hopefully not 'OpenNETCF.WindowsCE.MemoryManagement.MemoryLoad').

    Thursday, October 14, 2010 6:20 AM
  • Hi,

    to detect memory leaks in native code I have used a combination of DevHealth60 and Entrek CodeSnitch.

    DevHealth60 is good for finding the module that causes the memory leak and CodeSnitch can be used to instrument the module to pinpoint the origin of the leak.

    See here for more information

    DevHealth60: http://code.msdn.microsoft.com/DevHealth60

    CodeSnitch: http://www.entrek.com/codesnitch.html

    HTH,

    Bjoern

    Friday, October 15, 2010 6:41 AM
  • It seems the memory leak is in a driver, since my test-program does only the following:

    static void Main(string[] args) {
     while (true) {
      Console.WriteLine(OpenNETCF.WindowsCE.MemoryManagement.MemoryLoad);
      Thread.Sleep(500);
     }
    }
    
    @Bjoern: I use WinCE5. DevHealth60 seems to be for CE6
    Friday, October 15, 2010 8:10 AM
  • Doesn't the console window accumulate everything that you write to it?  That's not a leak; it's the expected behavior.

    Paul T.

    Friday, October 15, 2010 3:58 PM
  • What do you mean with 'accumulate' ?

    The Console.WriteLine statement writes out to the debug port over serial...

     

    UPDATE: it seems that the third-party wlan driver is causing the memory growth

    Monday, October 18, 2010 7:18 AM
  • In Windows CE/Mobile, we can use AppVerifer to detect memory/handle leak. In your scenario, if the memory allocated in unmanaged dll leak, AppVerifier can report the detail callstack to you.

    Below material for your reference:

    http://msdn.microsoft.com/en-us/library/aa446904.aspx

    http://download.microsoft.com/download/0/9/f/09fb0ed3-cc89-4f94-a022-c362902f50a2/UsingAppVerifierWindowsMobile.wmv

     

    Friday, October 22, 2010 2:55 PM