HI All,
I’m pretty stumped. I’m trying to hunt down a memory leak related to our display (garbage collection is manually triggered using GC.Collect() when memory is low - we’ve run into issues with events and timers throwing out of memory exceptions while GC is running). We’ve narrowed it down to certain on screen elements, but because, if I’m not mistaken, the display buffer is a fixed size, so I don’t understand why it cause a leak when certain regions are overwritten.
However, in an attempt to determine where the memory leak is by running GC before and after blocks of code to monitor memory usage over time, I’ve found that this memory leak only appears when running garbage collection infrequently - all the memory clears out just fine if I run the GC on time intervals of less than about 8 seconds.
Is there something under the hood in GC that would cause this behavior? I thought running GC every loop should still manifest a memory leak - it would just be tiny, but I’d be able to track growing memory usage over time. However, this only shows if GC runs only when needed.
GC response after about a minute of triggering the leak - Binary_Blob_Head is growing rapidly
GC Initialized
GC: 319msec 15034352 bytes used, 18520000 bytes available
Type 11 (STRING ): 63968 bytes
Type 13 (CLASS ): 5451152 bytes
Type 14 (VALUETYPE ): 36336 bytes
Type 15 (SZARRAY ): 76128 bytes
Type 01 (BOOLEAN ): 96 bytes
Type 03 (U1 ): 44240 bytes
Type 04 (CHAR ): 464 bytes
Type 07 (I4 ): 768 bytes
Type 0E (R8 ): 80 bytes
Type 11 (STRING ): 496 bytes
Type 13 (CLASS ): 27536 bytes
Type 14 (VALUETYPE ): 2448 bytes
Type 17 (FREEBLOCK ): 18520000 bytes
Type 19 (ASSEMBLY ): 40960 bytes
Type 1B (REFLECTION ): 96 bytes
Type 1D (DELEGATE_HEAD ): 3456 bytes
Type 1E (DELEGATELIST_HEAD ): 416 bytes
Type 1F (OBJECT_TO_EVENT ): 384 bytes
Type 20 (BINARY_BLOB_HEAD ): 6358032 bytes
Type 21 (THREAD ): 1600 bytes
Type 22 (SUBTHREAD ): 192 bytes
Type 23 (STACK_FRAME ): 1840 bytes
Type 24 (TIMER_HEAD ): 320 bytes
Type 29 (FINALIZER_HEAD ): 2984320 bytes
Type 33 (IO_PORT ): 336 bytes
Type 36 (APPDOMAIN_HEAD ): 80 bytes
Type 38 (APPDOMAIN_ASSEMBLY ): 14736 bytes
GC Method -
public static void RunGC(int loopcnt) { try { if(loopcnt % 100 == 0 || Helpers.freeBytes < 4000000) { GC.Collect(); //lets debugger know that the GC has been run Debug.WriteLine(" GC Initialized"); } } catch (Exception e) { Debug.WriteLine(e.Message); } }