Hi!
When I call function GarbageCollect(asGC_ONE_STEP),
GC don't destroy garbage.
Plase look sample code and output.
Library
r586 Debug Version
Compiler
MSVC8
sample code
void main()
{
// Create the script engine
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
// Register Function
RegisterScriptString(engine);
engine->RegisterGlobalFunction("void Print(string &in)", asFUNCTION(PrintString_Generic), asCALL_GENERIC);
// Compile
asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
mod->AddScriptSection("script",
"class Obj{};"
"class Hoge"
"{"
" Hoge(){ Print(\"ctor\\n\"); }"
" ~Hoge(){ Print(\"dtor\\n\"); }"
" Obj@ obj;"
"};"
"void main()"
"{"
" Hoge hoge;"
"};"
, 0);
mod->Build();
// Context Create
asIScriptContext *ctx = engine->CreateContext();
// Loop
while ( true )
{
// Execute
printf("----- execute\n");
ctx->Prepare(mod->GetFunctionIdByDecl("void main()"));
ctx->Execute();
// GC
const int GC_STEP_COUNT_PER_FRAME = 10000;
for ( int i = 0; i < GC_STEP_COUNT_PER_FRAME; ++i )
{
engine->GarbageCollect(asGC_ONE_STEP);
}
// Check status
{
asUINT currentSize = asUINT();
asUINT totalDestroyed = asUINT();
asUINT totalDetected = asUINT();
engine->GetGCStatistics(¤tSize , &totalDestroyed , &totalDetected );
printf("(%lu,%lu,%lu)\n" , currentSize , totalDestroyed , totalDetected );
}
// Wait to input key
while(!getch()){}
}
// Release
ctx->Release();
engine->Release();
}
output
----- execute
ctor
dtor
(8,1,0)
----- execute
ctor
(9,1,0)
----- execute
ctor
(10,1,0)
----- execute
ctor
(11,1,0)
----- execute
ctor
(12,1,0)
----- execute
ctor
(13,1,0)
----- execute
ctor
(14,1,0)
...
GC destroy garbage at the first time.
But GC don't destroy garbage after that.
Is this correct?