Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 9
    @Robert: A correctly written program cannot assume finalizers ever run. blogs.msdn.com/b/oldnewthing/archive/2010/08/09/10047586.aspx Commented Oct 30, 2013 at 16:52
  • 1
    Hm. Well, that's probably why they came up with the using statement. Commented Oct 30, 2013 at 16:54
  • 2
    Exactly. This is a huge source of newbie bugs in C++, and would be in Java/C# as well. Java/C# don't eliminate the ability to leak the reference to a resource that's about to be destroyed, but by making it both explicit and optional they remind the programmer and give him a conscious choice of what to do. Commented Oct 30, 2013 at 19:34
  • 1
    @svick It's not up to IWrapSomething to dispose of T. Whoever created T needs to worry about that, whether using using, being IDisposable itself, or having some ad-hoc resource lifecycle scheme. Commented Oct 30, 2013 at 19:42
  • 1
    @AleksandrDubinsky: Java and C# don't eliminate leaks. Careful design is still necessary to ensure you aren't referencing the whole world in terms of memory. They don't attempt to address non-memory resources at all, and failing to release a resource like this is a common source of bugs in Java and C# programs, because people don't pay as much attention to ownership as they should. Commented Nov 1, 2013 at 18:30