On Sun, Nov 17, 2013 at 9:21 AM, Andreas Falkenhahn
andr...@falkenhahn.comwrote:
Hi,
what's the recommended way to prevent objects from being garbage collected?
For example, I create a wxImageList and pass it to
wxNotebook::SetImageList().
As wxNotebook::SetImageList() doesn't take ownership of the list it could
happen that the garbage collector kills the wxImageList that I passed to
SetImageList().
To prevent it from being collected I could assign the wxImageList to a
global
variable but that doesn't look like a nice solution it would be nicer
if it were possible to reference the wxImageList somehow but I don't see
how this is possible. wxObject has a Ref() method but that doesn't seem to
be up for the job.
You're right, wxObject::Ref() is not what you want, in wxLua it will cause
a memory leak unless you remember to call UnRef() on it.
The best way is to either make it a global or attach the image list to some
other object that will live at least as long as the window it's attached
to.
You can also simply add it to the window itself.
local notebook = wx.wxNotebook(...)
local imagelist = wx.wxImageList(...)
notebook.imagelist = imagelist -- it is now a member of the notebook's table
notebook.SetImageList(imagelist)
Regards,
John
--
DreamFactory - Open Source REST JSON Services for HTML5 Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471iu=/4140/ostg.clktrk___
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users