What is difference between Dispose and Using?
What is difference between Dispose and Using? How to decide which one to use? Which is better option of garbage collection?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jun 4, 2014, 12:21 PM EDT
It's therefore a convenient alterative to calling the Dispose() method 'manually' within a try/catch/finally statement.
The Dispose() is designed to clear up 'unmanaged' resources used by an object such as file handles, database connections and the like as a prelude to the object itself being garbage collected.
It's preferable from a GC point of view to use the 'using' statement rather than calling Dispose() manually as this ensures that the object (if declared at the head of the statement) will automatically go out of scope when the 'using' statement ends and will become eligible for garbage collection without any delay.
Otherwise you have to remember to call Dispose() and then set the object variable to null manually. Failure to take these steps may lead to a resource leak or to the object hanging around in memory longer than it needs to.
Akhil MittalRank #133 · 16.9K reputationPosted Jun 4, 2014, 9:23 PM EDT