Skip to main content
11 events
when toggle format what by license comment
Jul 30, 2022 at 19:47 history edited kol CC BY-SA 4.0
deleted 11 characters in body
Jul 29, 2022 at 8:27 comment added JonasH "absolutely necessary", correctly written objects that own native resources should have a finalizer to clean up these resources when the object is collected, but this will be done at some indeterminate time. It is however very poor practice to rely on the finalizer.
Dec 20, 2011 at 0:09 vote accept one.beat.consumer
Dec 13, 2011 at 20:13 comment added MarkJ @one.beat You can easily tell which objects need manual disposing. They implement IDisposable. That means the API designer is telling you to dispose the object. Follow the instructions.
Dec 13, 2011 at 20:07 comment added one.beat.consumer @Kol do you have any other explicit examples from experience of objects that need manual disposing? Or any advice on smarter exception handling?
Dec 13, 2011 at 19:52 comment added one.beat.consumer @Kol - thank you for your response. I know what the using statement means and how it ties into IDisposable. Your SqlConnection thought is more like what I'm getting at... where the garbage collector will not be enough. things that need manual attention. And in terms of try/catch, how assertive a programmer should be about catching possible exceptions simply because the object is capable of throwing them.
Dec 13, 2011 at 19:34 history migrated from stackoverflow.com (revisions)
Dec 13, 2011 at 19:27 comment added kol Please be careful: for example in case of SqlConnection, you must use a using statement, or call Dispose directly, to close the DB connection. The garbage collector won't do this for you: "If the SqlConnection goes out of scope, it won't be closed. Therefore, you must explicitly close the connection by calling Close or Dispose." --source: msdn.microsoft.com/en-us/library/…
Dec 13, 2011 at 19:24 comment added mquander You have the wrong understanding. See my answer. IDisposable has nothing directly to do with garbage collection or memory. It is for cleaning up non-memory resources that also need to be cleaned up. Memory will take care of itself when an object goes out of scope, and trying to do it manually is not typically useful or necessary.
Dec 13, 2011 at 19:24 comment added one.beat.consumer My understanding is that .Net's garbage collection will cleanup IDisposable stuff on its own, and that these statements are to help programmers be assertive and manually control when and how they want it done. If that's the case, I'm trying to figure out the places its most important for me to do the work, and the places its safe to let the .Net runtime be the whiz-kid it's supposed to be.
Dec 13, 2011 at 19:20 history answered kol CC BY-SA 3.0