Jump to content
  • Advertisement
Sign in to follow this  
loboWu

memory leak about array reference

This topic is 4006 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!