Quote:Original post by TelastynQuote:Original post by Billr17
Because you cannot guarentee when the garbage collector will make a collection, you never want to fully rely on the destructor for cleanup.
And as an interesting note, .NET at least guarantees that the destructor will be called.
Java does not.
.NET:
"due to the non-deterministic nature of finalization the framework does not and cannot guarantee that the Finalize method will ever be called on an instance. Hence, you cannot rely upon this method to free up any un-managed resources (such as a file handle or a database connection instance) that would otherwise not be garbage collected by the GC."
-http://www.devx.com/dotnet/Article/33167/0/page/2
However in Java there's a sure-fire way to track object garbage collections using ReferenceQueues:
http://www.ibm.com/developerworks/java/library/j-refs/