Destructor semantics

bearophile bearophileHUGS at lycos.com
Wed Aug 11 13:26:58 PDT 2010


Don:
> As far as I can tell, the use cases for finalizers are very limited. To 
> me, destructors don't make any sense unless they are deterministic.
> For example, I think having a File class is probably a bug. You may be 
> on a system which has no limit on the number of file handles, but 
> generally, if you need resource management, you need a guarantee that 
> the destructor will be called.

This seems similar to what I have written before:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=115028
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=115057

But if the purpose of a destructor is just to help/speedup the deallocation of a RAM resource (like to nullify the links of a tree to speed up the job of the GC) then in my opinion it is acceptable for this destructor to not run deterministically.

Bye,
bearophile


More information about the Digitalmars-d mailing list