GC, the simple solution

Frank Benoit keinfarbton at nospam.xyz
Sun Jun 4 06:52:52 PDT 2006

Lionello Lunesu schrieb:
>> * Destructors are called immediatly if the counter goes zero.
> This is not such a good thing! You don't really know who releases the last 
> reference, so you don't really know when the object is deleted. If the 
> object is being referenced from multiple threads, you don't know in what 
> thread the destructor will run.

Where is the disadvantage? If you release concurrent in different
threads you need some kind of syncronization. Than you know it. But this
is no issue of ref counting.
If you release a reference in the phobos GC, the object is collected
"perhaps" the next time. If there are no valid integer values,
"pointing"to your object. And after collecting, the sequence of
destructor calls is not defined.

>> * all logic behaviour is deterministic
> See above.
See above.

>> * Member objects are still valid, while a destructor is called. => no
>> more dispose/close patterns
> When an object is being destructed, the references it has to other objects 
> are being released. So in the destructor of object B, object A might have 
> released about half its references.
If object B Dtor is called, its member variables are valid, and valid is
the object A. The B.~this() can do something with A. After the Dtor is
finished, the reference to A is nulled, and A is perhaps also deleted.
Seams perfect to me.

>> * consume only the needed memory
> What about circular references? They'll never get released, no clean-up.

Yes, they need a solution. Perhaps a fall back mark&sweep collector, to
check for cicles.

> L. 

More information about the Digitalmars-d mailing list