Bugs item #3064561, was opened at 2010-09-12 00:34
Message generated for change (Tracker Item Submitted) made by cperthuis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=745324&aid=3064561&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 wxlua_setderivedmethod
Initial Comment:
This one is pretty convoluted.
When you define a new function in lua on a lua object bound to a C++ object, if
the function happen to already exist, a "derived" method is added. This happens
in the wxlua_wxLuaBindClass__newindex callback.
If you do this on an object which is now owned by wx, and for which
wxluaO_undeletegcobject has been called ( with or without encapsulation ), a
reference on a the lua state will be kept and the entire lua memory will leak.
( which btw is pretty frustrating with the way wxLua is architectured, it's
usually a all or nothing thing, when something go bad, someone which was leaked
has a reference on the lua state, and the entire world is leaked...)
When the object is managed by wxLua and not by wx, then everything is fine,
since wxlua_removederivedmethods is called as part of wxluaO_deletegcobject.
Here's the fix I am suggesting: removing the reference on the wxLuaState kept
by the wxLuaObject class:
wxLuaObject::wxLuaObject(const wxLuaState& wxlState, int stack_idx)
: m_alloc_flag(wxLUAOBJECT_NONE),
m_int(0) // GCC only wants one initializer
{
m_wxlState = new wxLuaState(false);
m_wxlState->SetRefData(wxlState.GetRefData());
// set up the reference to the item on the stack
m_reference = m_wxlState->wxluaR_Ref(stack_idx, &wxlua_lreg_refs_key);
}
wxLuaObject::~wxLuaObject()
{
m_wxlState->SetRefData(NULL);
if (m_alloc_flag == wxLUAOBJECT_STRING)
delete m_string;
else if (m_alloc_flag == wxLUAOBJECT_ARRAYINT)
delete m_arrayInt;
// If a refererence exists, remove it, but don't bother if Lua is being
closed
if ((m_reference != LUA_NOREF) && m_wxlState->Ok() &&
!m_wxlState->IsClosing())
m_wxlState->wxluaR_Unref(m_reference, &wxlua_lreg_refs_key);
delete m_wxlState;
}
Btw, can someone comment and explain why there is this paranoia about keeping
refrenced on the lua state? I would have no one keeps any reference on it but
the system controlling the enter and the exit of the application. this would
fix all those issues.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=745324&aid=3064561&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