I'm trying to optimize memory usage of a program and therefore wants to remove objects when they aren't needed any longer. To check if this works correctly I wrote a console.writeline method in the destructor of the type of object I want to remove. However when I test the program, no lines are written (only when the program terminates of course).
Is there a way to get a list of object, events,... That keep a certain object alive and prevent it from being eliminated by the garbage collector. Or is there a profiler, debugger that can do this (MonoDevelop-compatible if possible)?
WinDbg + SOS can help understand that. But it takes time to learn that. For example,
Where's your leak at? [Using WinDbg, SOS, and GCRoot to diagnose a .NET memory leak]
cleanup occurrence is controlled by system, if your memory allocation is small enough and system didn't think it is necessary to cleanup than your destructor wont be called. it is not a best practice for production but you can force the GC by GC.Collect() use it only on test. If your destructor isn't call then there might be a leak.
i don't know profiler in mono environtment but this profiler is good enough in windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With