I am not sure how the user defined class objects are garbage collected. Do I need to implement IDisposable interface on every class and call the dispose() method on it to free the memory?
No. Every normal managed .NET object gets garbage collected when you stop referring to it. IDisposable means that you you will implement a Dispose() method that needs to be called by the caller -- it usually releases things that aren't garbaged collected. It also helps with having a deterministic place to release memory.
Check out the IDisposable pattern to make sure you do it right:
http://www.atalasoft.com/cs/blogs/stevehawley/archive/2006/09/21/10887.aspx
No, every object is disposed automatically.
IDisposable is usable when you have some kind of special operation to do at the object deconstruction. For example if you locks some resources like files or such during the work of your object, then you can release them in your Dispose method.
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