How to prevent the Memory Leak.

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.
 
M

Morten Wennevik

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.
 
G

Girish bharadwaj

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top