You should only worry about having an explicit Dispose() method when you are dealing with unmanaged objects (e.g. file handles ala FileStream) inside your object.
Main Topics
Browse All TopicsI have an object that's used extensively inside my program and I would like to add a Dispose function. It also contains a few of my own object types and I'd like to give them dispose fuctions as well. But is there a way to tie it into a Delete method?
OR, do I need to find every place in my program where it's no longer used and explicitly call Dispose()?
I'm a former C++ programmer and never really got the cleanup process mailed down the way I could in C++, since in C++ the whole task was my responsibility. And I have never really been certain about what I am to do cleaning up in C#.
So please show me how to create a Delete() method or explain that I need to add in Dispose() funtion calls.
Thanks,
newbieweb
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: jaime_olivaresPosted on 2009-11-07 at 09:35:20ID: 25767180
>> do I need to find every place in my program where it's no longer used and explicitly call Dispose()?
You are thinking like a C++ developer, you don't need to delete or dispose object instances. The garbage collector will know when an object is not needed (reference count=0).
Dispose() method is needed just in case your class/object contains a non-managed resource, like a GDI object, an SQL connection, or a file stream handler.