moechofe
Joined: 07 Oct 2006 Posts: 25 Location: Paris, France
|
Posted: Wed Apr 21, 2010 1:00 am Post subject: How to get finalizer called? |
|
|
I made a simple example, to observe that my finalizer function isn't called. Do I forgot something? Code: | module minidtestdelete;
import tango.util.log.Trace;
import minid.api;
pragma(lib,"DD-minid");
class S
{
this() { Trace("this"); }
~this() { Trace("~this"); }
static size_t allocator( MDThread* t, size_t num_params )
{
Trace("allocator()");
newInstance( t, 0, 0, S.sizeof );
dup(t);
pushNull(t);
rotateAll(t, 3);
methodCall(t, 2, "constructor", 0);
return 1;
}
static size_t constructor( MDThread* t, size_t num_params )
{
Trace("constructor()");
auto s = checkInstParam!(S)(t, 0, "S");
s = cast(S*)new S;
return 0;
}
static size_t finalizer( MDThread* t, size_t num_params )
{
Trace("finalizer()");
auto s = checkInstParam!(S)(t, 0, "S");
delete s;
return 0;
}
}
static ~this() { Trace("static destructor"); }
void main()
{
Trace(">"); scope(exit) Trace("<");
MDThread* t;
MDVM virtual_machine;
t = openVM( &virtual_machine );
loadStdlibs( t );
CreateClass( t, "S", (CreateClass* c)
{
c.method("constructor", &S.constructor);
});
newFunction(t, &S.allocator, "S.allocator");
setAllocator(t, -2);
newFunction(t, &S.finalizer, "S.finalizer");
setFinalizer(t, -2);
newGlobal(t, "S");
runString(t, "local test = S()");
} | And the result is: Code: | >
allocator()
constructor()
this
<
static destructor
~this |
Has you can see, the class destructor is called after the module destructor. Is a problem when using externals resources.
How I can fix that? |
|