Advertisement

memory leak about array reference

Started by October 31, 2007 03:23 AM
1 comment, last by loboWu 17 years, 4 months ago
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:

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

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
Thank you very much.

This topic is closed to new replies.

Advertisement