I have lots of memory allocated in my mono droid program which doesn't appear to directly belong to either the Dalvik or the Mono heaps. Also, I can't figure out how to track .NET memory leaks.
When I call
adb shell dumpsys meminfo MyProgram.Droid
This is the output:
** MEMINFO in pid 1364 [MyProgram.Droid] ** Shared Private Heap Heap Heap Pss Dirty Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ Native 36 24 36 38080 37775 124 Dalvik 6934 15164 6572 16839 15384 1455 Cursor 0 0 0 Ashmem 0 0 0 Other dev 4 36 0 .so mmap 12029 2416 9068 .jar mmap 0 0 0 .apk mmap 16920 0 0 .ttf mmap 3 0 0 .dex mmap 2299 296 8 Other mmap 64 24 36 Unknown 28920 8216 28728 TOTAL 67209 26176 44448 54919 53159 1579
I assume that the "Unknown" section is the mono framework, including the .NET heap. However when I call
GC.GetTotalMemory(true)
It tells me that only 5Mb of memory is allocated. That leaves 23Mb which I cannot trace (and there's 38Mb of allocated native heap)
Additionally, I don't see that Xamarin have any tools for tracking .NET memory leaks. I've added garbage collection logging with
adb shell setprop debug.mono.log gc,gref
But this is incredibly verbose and hard to read and doesn't even include allocation sizes.
At this point I don't know what to do to track down the resulting leaks. Since the allocations appear to be on the native heap, do I need to use the NDK in order to track down what's going on? Are there any tools I can use on the C# side to track the .NET leaks?
Thanks,
David
Posts
At this time I don't think there are any tools yet to help with this. I hope I am wrong; but this has been brought up several times.
If there really isn't any support for memory profiling then that makes it extremely hard to debug .NET memory allocations. At least with C++ you can override the new operator and roll your own profiler!