Class deallocator not being called -- bug or oversight?

Sean Kelly sean at f4.ca
Mon Sep 24 11:51:55 PDT 2007


Frits van Bommel wrote:
> Sean Kelly wrote:
>> Regan Heath wrote:
>>> Sean Kelly wrote:
>>>> Oh for what it's worth, I can't figure out where Phobos is calling 
>>>> class deallocators--the block I'd expect to be used in 
>>>> internal/gc/gc.d is commented out.  I don't suppose someone could 
>>>> test this with Phobos to see if it works?
>>>
>>> Works on Windows with DMD 2.004.
>>
>> Darnit, version(0) will get me every time.  That code is executed but 
>> it's the same as the old buggy Tango impl.  Ah well, as long as it 
>> works in Phobos...
> 
> Actually, there's an important difference:
> In Phobos the finalizer hander is only called from _d_delclass directly 
> when a deallocator is present, necessarily *after* the classinfo 
> reference has been loaded from the vtable since the deallocator is 
> stored in the classinfo. (If no deallocator is present, the finalizer 
> handler is called from somewhere inside _gc.free()).
> In Tango, on the other hand, you always call the finalizer handler from 
> _d_delclass. You used to do this *before* loading the classinfo 
> reference from the vtable.

You're right of course.  I should really learn to not post while I'm 
still waking up :-)

> Now for the important bit: in both libs, the finalizer handler _nulls 
> the vptr_. That means that in Tango it used to do so before the lookup 
> of the classinfo in the vtable, while in Phobos the classinfo lookup was 
> always performed before the finalizer handler is called.

Yup.  In hindsight, the side-effect makes sense, but I'd overlooked it 
when changing the behavior of _d_delclass way back when.


Sean


More information about the Digitalmars-d-learn mailing list