How to prevent the Memory Leak.

  • Thread starter Thread starter vasu
  • Start date Start date
V

vasu

Hi All,



I am working on C#.net. I am facing the problem in releasing the memory. As
far as I know, .Net having the provision for automatic garbage collector.
But I don't know when that will be called. I am using the Dispose method on
unreferenced object to release the memory before the Garbage collector is
called. Still I am facing the problem of memory leak.



Please anyone can suggest me, how to prevent the memory leak in C#.Net.



Thanks in Advance,

Vasu.
 
Hi Vasu

Dispose does not release the memory. Dispose releases unmanaged resources used by an object, like file handles.

When you are done with an object, after calling Dispose make sure the object isn't referenced anywhere (ie the reference either goes out of scope, or you set it to null). The garbage collector will eventually release the memory. When this happens depends on how much memory your program uses and how much free memory your system has.
 
You can potentially call GC.Collect() but there are several caveats
associated with it. Just make sure that you have read up on it before
calling it.
 
Back
Top