Defining a custom *constructor* (not initializer!)
Steven Schveighoffer
schveiguy at yahoo.com
Mon May 7 12:46:29 PDT 2012
On Mon, 07 May 2012 15:09:34 -0400, Mehrdad <wfunction at hotmail.com> wrote:
> Oh, and ditto with the destructor: I need to be able to call the
> destructor manually, because the C does that inside a callback on my
> behalf.
You definitely can do this. I think it's just __dtor. But I'm not sure if
that calls the whole chain. rt_finalize, the function that actually calls
the dtors calls each dtor in the chain individually. You can see how it
works here:
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1161
However, if C is calling your dtor, I'd highly recommend *not* using GC
memory for your class data, you can std.conv.emplace it in C-malloced
memory. If it has any references to GC data, use GC.addRoot to make sure
that data isn't accidentally collected, and use GC.removeRoot before
destruction.
-Steve
More information about the Digitalmars-d
mailing list