GC object finalization not guaranteed

Robert Jacques sandford at jhu.edu
Sat Apr 18 08:56:16 PDT 2009


On Sat, 18 Apr 2009 11:24:14 -0400, Leandro Lucarella <llucax at gmail.com>  
wrote:
> I've just found out[1] this[2]:
>
> 	The garbage collector is not guaranteed to run the destructor for
> 	all unreferenced objects.
>
> Is there any reason why D can't guarantee that all finalizers will be
> called, at least when the program ends?

Well, a couple of quick tests show that under normal situations (i.e.  
normal program termination and termination from an exception) the  
finalizers do run (D2). However, if a finalizer throws an exception, then  
the rest of the finalizers aren't called. Also, if you call  
std.c.stdlib.exit, the finalizers won't run.



More information about the Digitalmars-d mailing list