John Labenski <jlaben...@...> writes: > > On Sat, Apr 25, 2009 at 1:11 PM, lostgallifreyan > <lostgallifre...@...> wrote: . . > > local DC,P=wx.wxMemoryDC(),wx.wxPen() P:SetWidth(5) > > P:SetStyle(wx.wxSOLID) > > DC:SelectObject(BITMAP) DC:SetPen(P) DC:SetBrush(wx.wxTRANSPARENT_BRUSH) > > for N=0,255,5 do > > P:SetColour(N,N,N) DC:SetPen(P) DC:DrawLine(N,0,N,100) > > end > > DC:SelectObject(wx.wxNullBitmap) P:delete() > > DC:delete() > > > > The code above is fine since the C++ wxPen::SetColour() code simply > calls wxColour::Set(r,g,b) on the internal wxColour member of the > wxPen. More generally; in wxLua you don't have to worry about deleting > any objects that are not explicitly created by you in wxLua or > returned by another function. We will trust that there are no memory > leaks in wxWidgets itself, which is a safe bet. >
Cool, I guess that means I'd have to watch it if I used GetColour(), as in that case I'd have an actual colour object on my hands if I didn't extract its values then immediately delete it. > You can print out all the objects in wxLua including ones that are > installed at startup: > for k,v in pairs(wxlua.GetTrackedObjectInfo()) do print(k, v) end > > and also only the objects that you have created that need to be or > will be deleted when they go out of scope and the garbage collector > runs: > for k,v in pairs(wxlua.GetGCUserdataInfo()) do print(k, v) end > > ======================== > example in wxLuaEdit in the console in the bottom: > > p = wx.wxPen(wx.wxColour(1,2,3), 1, 1) > for k,v in pairs(wxlua.GetGCUserdataInfo()) do print(k, v) end > 1 wxColour(0x29846f0) > 2 wxPen(0x2952780) > collectgarbage('collect') > for k,v in pairs(wxlua.GetGCUserdataInfo()) do print(k, v) end > 1 wxPen(0x2952780) > Very nice. Thankyou. I'll add those to my collection of test flags. :) > The most "dangerous" problem with GC in wxLua are those hidden objects > like the wxColour above and there's no way to keep track of them. I > can't think of any clever way that would be much better than simply > calling the Lua function collectgarbage("collect"). > Fine by me, it's built into Lua's core so I want to learn its use anyway. Your advice will help me find the time and place to do it. One thing I've noticed is that when loading a large bitmap, I get one or two shots at it providing each load and close of the program is clean. If I try too soon the bitmap loads but is not displayed! Conversely if I leave the program sitting for a while, I can expect to close and reload and have it display more that twice per session without reboot. If it borks and fails to display, that's it, end of session, need reboot. (This is W98 SE). I have tried collectgarbage("collect") at various points already during yesterday's work, without results, but the fact that I can wait a while and thus get clearance to load it again safely imp;ies that some sort of garbage collection might be happening, and possibly in Windows itself? If you have any thoughts that might help track down a way to invoke it manually, it coule allow me to safely load a huge image any number of times without causing that display failure. One other clue: I've seen similar errors in other programs, which is why I'm convinced this is something in Windows. Crucially, tools like Paint Shop appear to be able to reload the image as often as I like without error, so that implies there IS a way, though whether it's something wxLua can reach I don't know yet. ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensign option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users