On 24-05-2012 14:43, Michel Fortin wrote:
On 2012-05-24 12:21:01 +0000, Alex Rønne Petersen <a...@lycus.org> said:

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 think it means that objects not collected when the program terminates
will never be, and thus the destructor will not be called.

That's silly. Microsoft .NET and Mono have been running finalizers on runtime shutdown for a long time without problems.


There's also the issue of false pointers that can prevent some objects
from being collected.

Right, but I think if we guarantee finalization at shutdown, that shouldn't matter.


More generally, you can't really count on the destructor being called
because the GC is free to decide when to recycle memory. An
implementation that never collects and always allocate new memory is a
perfectly valid GC implementation, even though it might not be very
practical in most cases.


Even such an implementation should free all memory at shutdown, and, at that point, run finalizers.

--
Alex Rønne Petersen
a...@lycus.org
http://lycus.org

Reply via email to