Delegates, references and module discard

Started by
5 comments, last by WitchLord 2 years, 1 month ago

There is code:

class TestDeleteDelegate {
    uint k = 0;
    ~TestDeleteDelegate() {
        Print("~TestDeleteDelegate");
    }
    void func() {
        Print("func " + k);
    }
};

funcdef void vv();
vv@ funcRef;

void testDelDelegate() {
    TestDeleteDelegate tdd;
    tdd.k = 10;
    @funcRef = vv(tdd.func);
}

int main() {
    testDelDelegate();
    funcRef();
    return 0;
}

When I run this and call module→Discard, I get output:

func 10
~TestDeleteDelegate
>>> warning: There is an external reference to an object in module 'test', preventing it from being deleted
>>> warning: The function in previous message is named 'main'. The func type is 1
>>> warning: There is an external reference to an object in module 'test', preventing it from being deleted
>>> warning: The function in previous message is named '~TestDeleteDelegate'. The func type is 1
>>> warning: There is an external reference to an object in module 'test', preventing it from being deleted
>>> warning: The builtin type in previous message is named 'TestDeleteDelegate'

Why references not cleared correctly on discard module?

Advertisement

Hi Alexander,

this looks like a bug. It certainly should be able to properly discard the module and free the memory in this case. I'll need to investigate this.

Thanks for bringing it to me.

Andreas

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

Although the problem is probably somewhere in my integration code. I ran this code in asrun - it worked fine there.

Can you identify what you're doing differently than I do in asrun?

If it works in asrun as you say then I probably won't be able to reproduce the problem without knowing what you do differently, but I'll give it a try.

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

Thanks for support. Turns out it's my bug. Two points: in ny implementation when returning the context to the pool, I did not call the Unprepere for it, and before turning off the engine, I did not release the contexts from the pool.

void asReturnContext(asIScriptEngine* engine, asIScriptContext* ctx, void*) {
    ctx->Unprepare();
    contextPool.push_back(ctx);
}
...
for (auto c : contextPool)
    c->Release();
asEngine->ShutDownAndRelease();

and all worked fine.

Great, thanks for the update.

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

This topic is closed to new replies.

Advertisement