Bugs item #3064520, was opened at 2010-09-11 22:17
Message generated for change (Tracker Item Submitted) made by cperthuis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=745324&aid=3064520&group_id=140042
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Cedric Perthuis (cperthuis)
Assigned to: Nobody/Anonymous (nobody)
Summary: memory leaks due to encapsulation classes
Initial Comment:
Hi,
Each time the construction if (wxluaO_isgcobject(L, dataObject))
wxluaO_undeletegcobject(L, dataObject); for an object which requires an
encapsulation class, ie for each object which is not derived from wxObject, the
encapsulation class itself is not referenced by anyone anymore and is leaked.
so I suggest to add a function to get the wxObject referenced in the garbage
collector table:
wxObject *LUACALL wxluaO_getcgobject(lua_State *L, void *obj_ptr)
{
lua_pushlightuserdata(L, &wxlua_lreg_gcobjects_key); // push key
lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push
value (table)
lua_pushlightuserdata(L, obj_ptr); // push key
lua_rawget(L, -2); // get t[key] = value, pops key
wxObject* obj = NULL;
bool found = lua_islightuserdata(L, -1);
if (found)
{
obj = (wxObject*)lua_touserdata(L, -1);
}
lua_pop(L, 2); // pop udata and table
return obj;
}
Then for all the wxluaO_undeletegcobject called on classes which use the
encapsulation then change the generated code to do this:
if (wxluaO_isgcobject(L, dataObject))
{
//We have an encapsulated object, we can't just remove
the referenced object from the list, the encapsulation instance needs to be
deleted
wxLua_wxObject_wxTextDataObject *obj =
(wxLua_wxObject_wxTextDataObject *)wxluaO_getcgobject(L,dataObject); //it
doesn't matter which class we use to cast, they all have the data pointer at
the same offset
obj->m_pwxTextDataObject = NULL; //set NULL to make
sure the delete doesn't destroy anything
delete obj;
wxluaO_undeletegcobject(L, dataObject);
}
Note that it doesn't matter which encapsulation class is used to clear the
pointer and to call delete. what's important is to clear the pointer and then
call delete.
thanks,
Cedric.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=745324&aid=3064520&group_id=140042
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
wxlua-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxlua-users