The Dispose
method is used for releasing unmanaged resources.
When all references to an object are removed, the garbage collector will eventually "Collect" it (freeing the memory). You can't actually control when this happens, even calling GC.Collect
is technically just a suggestion. You can, however, invoke dispose on an object directly (note that this may cause odd behavior or exceptions if it is still in use!)
If you suspect a control has unmanaged resources that need to be cleaned up, you should call Dispose
on it directly when you are finished with it (GDI Bitmap objects need to be cleaned up like this). From your comments, it sounds like you just need the garbage collector to actually free the memory, which is something thats hard to control (you can try calling GC.Collect
though).
MSDN for Dispose: http://msdn.microsoft.com/en-us/library/system.idisposable.aspx