On Thu, 24 May 2012 08:54:45 -0400, Peter Alexander
<peter.alexander...@gmail.com> wrote:
On Thursday, 24 May 2012 at 12:21:02 UTC, Alex Rønne Petersen wrote:
Hi,
http://dlang.org/class.html#Destructor
"The garbage collector is not guaranteed to run the destructor for all
unreferenced objects."
What the *hell*? So resources are allowed to arbitrarily leak and the
programmer has to actually expect this to happen?
I really, really hope that this is a documentation error or early
design decision that has since been rectified but with lack of
documentation updates.
I'm pretty sure it's the same in Java.
Finalizers (a.k.a. class destructors) are practically useless.
From Java spec:
"The Java programming language does not specify how soon a finalizer will
be invoked, except to say that it will happen before the storage for the
object is reused"
So yeah, there is no guarantee when a finalizer will be invoked.
However, I'd tend to believe Java implementations will attempt to invoke
all finalizers of objects left on the heap at program shutdown.
I think D is the same too, as long as termination is normal (i.e. not from
throwing an Error).
-Steve