Projects > cpp > Issues > Bug #3345

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

CCLayer unregisterScriptHandler lead to LUA table TOLUA_REFID_FUNCTION_MAPPING memory leak

Bug #3345 [Closed]
a@olsoft.net 2013-12-04 10:56 . Updated about 2 years ago

on called CCLayer some registerScriptHandler method,
just like registerScriptTouchHandler method,
it’s auto call toluafix_ref_function method,
save the callback argument into TOLUA_REFID_FUNCTION_MAPPING table.

TOLUA_API int toluafix_ref_function(lua_State* L, int lo, int def)
{
//some code..
    s_function_ref_id++;
    lua_pushstring(L, TOLUA_REFID_FUNCTION_MAPPING);
    lua_rawget(L, LUA_REGISTRYINDEX);                           /* stack: fun ... refid_fun */
    printfStackData( L );
    lua_pushinteger(L, s_function_ref_id);                      /* stack: fun ... refid_fun refid */
    lua_pushvalue(L, lo);                                       /* stack: fun ... refid_fun refid fun */
    lua_rawset(L, -3);                  /* refid_fun[refid] = fun, stack: fun ... refid_ptr */
    lua_pop(L, 1);                                              /* stack: fun ... */
    return s_function_ref_id;
}

but on call registerScriptHandler method,
it’s don’t auto call toluafix_remove_function_by_refid method
to delete before saved callback argument. it’s only release scriptHandlerEntry.

 void CCLayer::unregisterScriptKeypadHandler(void)
{
        CC_SAFE_RELEASE_NULL(m_pScriptKeypadHandlerEntry);
}

THE PROBLEM LEAD TO LUA TABLE “TOLUA_REFID_FUNCTION_MAPPING” MEMORY LEAK!

I THINK NEED TO MODIFY LIKE:

 void CCLayer::unregisterScriptKeypadHandler(void)
{
    if( m_pScriptKeypadHandlerEntry != NULL )
    {
        toluafix_remove_function_by_refid( m_pScriptKeypadHandlerEntry->getHandler() );
        CC_SAFE_RELEASE_NULL(m_pScriptKeypadHandlerEntry);
    }
}
a@olsoft.net 2013-12-04 11:03

SORRY, ORRIANAL TEXT
“but on call registerScriptHandler method” IS WRONG!

DODIFY:
“but on call unregisterScriptHandler method”

a@olsoft.net 2013-12-04 13:40

WOW…OK. PLEASE CLOSE THE TICKET.

in some Objects just like CCLayer,
unregisterScriptHandler method trigger ScriptHandlerEntry instance release,
and on ScriptHandlerEntry instance destruct, call the toluafix_remove_function_by_refid method.

BUT, other some Objects like CCItem,
in unregisterScriptHandler direct call the toluafix_remove_function_by_refid method.

HOPE FOR UNIFORM STYLE. ;)

walzer@cocos2d-x.org 2014-10-08 02:45

Redmine issue system is closed, we are using github issue system instead.

This issue was moved to https://github.com/cocos2d/cocos2d-x/issues/8275

Atom PDF

Status:Closed
Start date:2013-12-04
Priority:Low
Due date:
Assignee:-
% Done:

0%

Category:lua, native client
Target version:-

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.