asCScriptFunction::~asCScriptFunction()
{
// Dummy functions that are allocated on the stack are not reference counted
asASSERT( funcType == asFUNC_DUMMY ||
(externalRefCount.get() == 0 && internalRefCount.get() == 0) );
+ printf(" + destruct %s\n", name.AddressOf());fflush(stdout);
First of all, prepare as above.
static const char *script1 =
"shared class X { } \n"
"X@ x = X();"
;
static const char *script2 =
"shared class X { }; \n"
"void test() { \n"
"} \n"
;
bool Test()
{
bool fail = false;
int r;
CBufferedOutStream out;
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &out, asCALL_THISCALL);
asIScriptModule *mod = engine->GetModule("Module1", asGM_ALWAYS_CREATE);
mod->AddScriptSection("Script1", script1, strlen(script1), 0);
mod->Build();
out.buffer = "";
mod = engine->GetModule("Module2", asGM_ALWAYS_CREATE);
mod->AddScriptSection("Script2", script2, strlen(script2), 0);
r = mod->Build();
if( r < 0 ) TEST_FAILED;
if( out.buffer != "" )
TEST_FAILED;
// discard `Module2`
mod->Discard();
// game loop
for(unsigned i = 0; i < 10; ++i) {
engine->GarbageCollect(); // run DeleteDiscardedModules();
PRINTF(".");
}
PRINTF("gameloop done.\n");
engine->Release();
// Success
return fail;
}
And then execute the above.
..........gameloop done.
+ destruct test
The result will be as above. This indicates that `void test ()` was
not deleted until the game loop terminated.
+ destruct test
..........gameloop done.
Applying a patch to `asCModule :: HasExternalReferences` will result
in the above.