🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
memory leak about array reference
In AS 2.10.0
I registered a global function
r = engine->RegisterGlobalFunction("void TEST(uint8[] @)", asFUNCTION(TEST_ARRAY), asCALL_CDECL); assert( r >= 0 );
// here is the C function
static void TEST_ARRAY(asIScriptArray* cmd)
{
CString str;
str.Format(_T("%d"),*(uint8*)cmd->GetElementPointer(0));
AfxMessageBox(str);
}
and I write a small test script
void main()
{
uint8[] input(10);
input[0]=100;
input[1] = 102;
TEST(input);
}
the result is just what I want. But memory leak detected when closing APP.
If I replace the global function like that:
r = engine->RegisterGlobalFunction("void TEST(uint8[] &inout)", asFUNCTION(TEST_ARRAY), asCALL_CDECL); assert( r >= 0 );
Everything is fine, and no memory leak.
This bug just occur with registered function, the "array reference" parameter in script function doesn't raise memory leak.
Since you're receiving an object handle, you must release the reference if you're not going to store it for later use. You can also register the function with auto-handles if you wish to have AngelScript release the handle for you.
Either this:
or this:
Regards,
Andreas
Either this:
r = engine->RegisterGlobalFunction("void TEST(uint8[] @)", asFUNCTION(TEST_ARRAY), asCALL_CDECL); assert( r >= 0 );static void TEST_ARRAY(asIScriptArray* cmd){CString str;str.Format(_T("%d"),*(uint8*)cmd->GetElementPointer(0));AfxMessageBox(str);cmd->Release();}
or this:
r = engine->RegisterGlobalFunction("void TEST(uint8[] @+ )", asFUNCTION(TEST_ARRAY), asCALL_CDECL); assert( r >= 0 );static void TEST_ARRAY(asIScriptArray* cmd){CString str;str.Format(_T("%d"),*(uint8*)cmd->GetElementPointer(0));AfxMessageBox(str);}
Regards,
Andreas
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement