Reputation: 995
I want to know if really memory is getting leaked. My Scenaio is like:
Is this a memory leak or could be a situation that garbage collector have not cleared the memory.
And as events are also considered as references. what if the event is present in a dereferenced object? then that event would not be considered as a reference, right?
Upvotes: 5
Views: 532
Reputation: 1074
In .Net once you dont reference an object the object is collected back. If you have a live reference then the object is kept alive. So to find a memory leak you need to do the following
You can either do this with some memory profiler or you can use WinDbg+sos. People feel windbg is hard to use but for these cases windbg+sos is much more easier to use and it is free. Also you will feel happy after fixing the leak. you will be one among those who always prefers free powerful tools.
Have a look at this link.
http://blogs.msdn.com/b/ricom/archive/2004/12/10/279612.aspx
Upvotes: 1
Reputation: 4369
Memory is only garbage collected when needed, more technical when the so called Generation 0 is full or when the overall system memory pressure is suficcient to force a garbage collection. Memory is not automatically reclaimed when it goes out of scope. More info here and here.
Just for testing, try calling GC.Collect()
after closing the dialog (after it is no longer referenced) to force the GC to collect any available memory.
In reality, you should not fiddle with the Garbage Collector, it is heavily tuned for best performance.
If you suspect that you are indeed leaking memory, use some kind of memory profiler to analyze your application.
Try for example RedGates Memory Profiler, they have a time-based trial.
Follow this walk-through to get up to speed and learn a bit what to look for and how.
Upvotes: 2
Reputation: 1466
It could be a situation that garbage collector have not cleared the memory
Upvotes: -1
Reputation: 54127
How about using a memory profiling tool such as JetBrains dotTrace to profile the memory usage of your application?
Upvotes: 0
Reputation: 49271
The garbage collector frees only objects that aren't referenced anymore.
It doesn't magically remove all the objects you don't want anymore.
Check if you still have references to any of the objects. Remember that events are also considered references. (It needs to know which object to go to)
Upvotes: 10