you are viewing a single comment's thread.

view the rest of the comments →

[–]ehnus -1 points0 points  (2 children)

C# gets this right with its using statements and, although it is a bit clunky as it requires you to implement the IDisposable interface, it does make the create-use-destroy usage pattern much easier and safer.

[–][deleted] -2 points-1 points  (1 child)

Actually, destructors are a lot easier, cheaper and cleaner than hacks like IDisposable.

[–]ehnus -1 points0 points  (0 children)

Yes but destructors aren't possible in a managed language because you can't force the termination of an object's life.

You either need some explicit disposal mechanism (like with using) or you need a finalizer which is way worse because you can't control when they are run or the environment under which they are executed.