Advertisement

GC not destroy garbage with asGC_ONE_STEP

Started by April 15, 2010 09:50 AM
2 comments, last by hoboaki 14 years, 7 months ago
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(&currentSize , &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?
No this is not correct. I'll have to investigate this.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
I've found and fixed the bug in the incremental garbage collector. The problem was that it didn't restart the cycle when no more garbage was found.

Diff for as_gc.cpp.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I confirmed that this bug was fixed.
Thank you!

This topic is closed to new replies.

Advertisement