Destructor nonsense on dlang.org

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu May 24 09:10:39 PDT 2012


On 5/24/12 10:27 AM, deadalnix wrote:
> Le 24/05/2012 16:54, Andrei Alexandrescu a écrit :
>> On 5/24/12 9:28 AM, Alex Rønne Petersen wrote:
>>> The GC should (and probably does) assume at shutdown that all objects
>>> are unreferenced, and therefore reclaim and finalize them.
>>
>> They may refer to one another.
>>
>> Andrei
>>
>
> So what ?
>
> Each GC passes must, mark object that have to be removed, call finalizer
> on them all, THEN recycle memory.
>
> So « zombie » object can still refer to one another in finalization.

This is possible but not trivial as the state of zombie objects must be 
properly defined. Often such objects will fail their invariant (a 
reasonable state of a zombie object is with the correct vtable, no 
mutex, and all fields in the pre-constructor state).

> The real problem is resurrection, which should be 100% forbiden and this
> must be enforced by the language (ie, the scopeness of this parameter is
> something important).

As one aspect, calls to new should fail during destruction.


Andrei


More information about the Digitalmars-d mailing list