On 17.11.2013 at 19:37 John Labenski wrote: > On Sun, Nov 17, 2013 at 9:21 AM, Andreas Falkenhahn > <andr...@falkenhahn.com>wrote:
> > 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) Ok, thanks. -- Best regards, Andreas Falkenhahn mailto:andr...@falkenhahn.com ------------------------------------------------------------------------------ Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now. http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk _______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users