Class deallocator not being called -- bug or oversight?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Mon Sep 24 10:52:14 PDT 2007


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.
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.


More information about the Digitalmars-d-learn mailing list