I had some very wrong sounding advice recently from a \"senior\" developer/coworker regarding the C# garbage collector such as...
\"You need to use destructors
The advice you've been given is, broadly speaking, a load of hooey.
Both C# and Java have GCs that attempt to optimise the fast recovery of lots of small objects. They're designed to solve the same problem, they do it in slightly different ways but as a user the technical differences in your approach to using them is minimal, even non-existent for the majority of users.
IDisposable
is nothing to do with the GC as such. It's a standard way of naming methods that would otherwise be called close
, destroy
, dispose
, etc., and often are called that in Java. There is a proposal for Java 7 to add something very similar to the using
keyword that would call a similar close
method.
"Destructors" in C# refers to finalizers - this was done deliberately to confuse C++ programmers. :) The CLR spec itself calls them finalizers, exactly as the JVM does.
There are many ways in which Java and C#/CLR differ (user value types, properties, generics and the whole family of related features known as Linq), but the GC is one area where you can develop a substantial amount of software before you need to worry much about the difference between them.