Destructor nonsense on dlang.org

Alex Rønne Petersen alex at lycus.org
Thu May 24 09:12:36 PDT 2012


On 24-05-2012 18:10, Andrei Alexandrescu wrote:
> 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

Finalization happens once the world has been resumed, meaning GC 
allocation (and even explicit deallocation) should be perfectly safe. 
This is absolutely essential: Finalization models where finalizers run 
in a paused world are doomed to fail miserably.

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d mailing list