Alex Fenton
2007-May-21 18:56 UTC
[Wxruby-development] First drop of new memory management
Hi Just a quick update on memory leaks etc. I''ve just dropped a bunch of patches with a new approach to linking ruby''s GC to Wx''s memory handling. Still some work to do - eg bigdemo.rb falls over quite quickly - but working well for me on other samples. Briefly, it disposes of fixdeleting. For almost all objects that aren''t Windows, they should now be deleted when the ruby object has fallen out of scope and garbage collection is done. This is normal SWIG behaviour. So this should address memory leaks eg with Wx::Bitmap. Windows are a bit different, as they may not be referenced by any ruby variable, but still very much alive displayed on the screen. The instance of Wx::App now listens for all notifications of windows being destroyed from WxWidgets (via wxWindowDestroyEvent). In ruby''s GC mark phase, all known SWIG objects are checked, and if they point to a Window that hasn''t yet been destroyed, they are marked to prevent them being destroyed. Anyway, apologies if you find things a bit shaky for a little while - shout with other samples you find to be crashing. But should be worth it to fix wxRuby''s bad memory habits, and more maintainable too. alex
Alex, I just got done going over the DIFFs from the changes and the way you have it setup looks slick to me, not to mention well documented and maintainable. I am going to update and compile now. Great work! Sean On 5/21/07, Alex Fenton <alex at pressure.to> wrote:> Hi > > Just a quick update on memory leaks etc. I''ve just dropped a bunch of > patches with a new approach to linking ruby''s GC to Wx''s memory > handling. Still some work to do - eg bigdemo.rb falls over quite quickly > - but working well for me on other samples. > > Briefly, it disposes of fixdeleting. For almost all objects that aren''t > Windows, they should now be deleted when the ruby object has fallen out > of scope and garbage collection is done. This is normal SWIG behaviour. > So this should address memory leaks eg with Wx::Bitmap. > > Windows are a bit different, as they may not be referenced by any ruby > variable, but still very much alive displayed on the screen. The > instance of Wx::App now listens for all notifications of windows being > destroyed from WxWidgets (via wxWindowDestroyEvent). In ruby''s GC mark > phase, all known SWIG objects are checked, and if they point to a Window > that hasn''t yet been destroyed, they are marked to prevent them being > destroyed. > > Anyway, apologies if you find things a bit shaky for a little while - > shout with other samples you find to be crashing. But should be worth it > to fix wxRuby''s bad memory habits, and more maintainable too. > > alex > > > _______________________________________________ > Wxruby-development mailing list > Wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >
The first problem I have found is with resizing windows, it crashes with multiple samples. Here is the output of the printing sample when running ruby in debug mode: Exception `LoadError'' at /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27 - no such file to load -- wx /usr/local/lib/ruby/gems/1.8/gems/wxruby2-preview-0.0.41-i686-darwin8.8.2/lib/wx/classes/app.rb:10: warning: method redefined; discarding old on_assert_failure /usr/local/lib/ruby/gems/1.8/gems/wxruby2-preview-0.0.41-i686-darwin8.8.2/lib/wx/classes/clientdc.rb:8: warning: method redefined; discarding old initialize /usr/local/lib/ruby/gems/1.8/gems/wxruby2-preview-0.0.41-i686-darwin8.8.2/lib/wx/classes/paintdc.rb:7: warning: method redefined; discarding old initialize /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32: warning: instance variable @__wx_destroyed__ not initialized /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32: warning: instance variable @__wx_destroyed__ not initialized /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32: warning: instance variable @__wx_destroyed__ not initialized /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32: warning: instance variable @__wx_destroyed__ not initialized printing.rb:480: [BUG] Bus Error ruby 1.8.5 (2006-12-25) [i686-darwin8.8.2] Abort trap Sean On 5/21/07, Sean Long <sean.m.long at gmail.com> wrote:> Alex, > > I just got done going over the DIFFs from the changes and the way you > have it setup looks slick to me, not to mention well documented and > maintainable. > > I am going to update and compile now. > > Great work! > > Sean > > On 5/21/07, Alex Fenton <alex at pressure.to> wrote: > > Hi > > > > Just a quick update on memory leaks etc. I''ve just dropped a bunch of > > patches with a new approach to linking ruby''s GC to Wx''s memory > > handling. Still some work to do - eg bigdemo.rb falls over quite quickly > > - but working well for me on other samples. > > > > Briefly, it disposes of fixdeleting. For almost all objects that aren''t > > Windows, they should now be deleted when the ruby object has fallen out > > of scope and garbage collection is done. This is normal SWIG behaviour. > > So this should address memory leaks eg with Wx::Bitmap. > > > > Windows are a bit different, as they may not be referenced by any ruby > > variable, but still very much alive displayed on the screen. The > > instance of Wx::App now listens for all notifications of windows being > > destroyed from WxWidgets (via wxWindowDestroyEvent). In ruby''s GC mark > > phase, all known SWIG objects are checked, and if they point to a Window > > that hasn''t yet been destroyed, they are marked to prevent them being > > destroyed. > > > > Anyway, apologies if you find things a bit shaky for a little while - > > shout with other samples you find to be crashing. But should be worth it > > to fix wxRuby''s bad memory habits, and more maintainable too. > > > > alex > > > > > > _______________________________________________ > > Wxruby-development mailing list > > Wxruby-development at rubyforge.org > > http://rubyforge.org/mailman/listinfo/wxruby-development > > >
I did not realize I was not running a debug build, here is the terminal output: Calling wxEntry, this=0x6e41e0 === Starting App GC mark phase === App GC mark phase completed printing.rb:480: [BUG] Segmentation fault ruby 1.8.5 (2006-12-25) [i686-darwin8.8.2] Abort trap So the crash is right after the App GC mark phase, when I resize the window. Sean On 5/21/07, Sean Long <sean.m.long at gmail.com> wrote:> The first problem I have found is with resizing windows, it crashes > with multiple samples. > > Here is the output of the printing sample when running ruby in debug mode: > Exception `LoadError'' at > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27 - no > such file to load -- wx > /usr/local/lib/ruby/gems/1.8/gems/wxruby2-preview-0.0.41-i686-darwin8.8.2/lib/wx/classes/app.rb:10: > warning: method redefined; discarding old on_assert_failure > /usr/local/lib/ruby/gems/1.8/gems/wxruby2-preview-0.0.41-i686-darwin8.8.2/lib/wx/classes/clientdc.rb:8: > warning: method redefined; discarding old initialize > /usr/local/lib/ruby/gems/1.8/gems/wxruby2-preview-0.0.41-i686-darwin8.8.2/lib/wx/classes/paintdc.rb:7: > warning: method redefined; discarding old initialize > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32: > warning: instance variable @__wx_destroyed__ not initialized > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32: > warning: instance variable @__wx_destroyed__ not initialized > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32: > warning: instance variable @__wx_destroyed__ not initialized > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32: > warning: instance variable @__wx_destroyed__ not initialized > printing.rb:480: [BUG] Bus Error > ruby 1.8.5 (2006-12-25) [i686-darwin8.8.2] > > Abort trap > > Sean > > On 5/21/07, Sean Long <sean.m.long at gmail.com> wrote: > > Alex, > > > > I just got done going over the DIFFs from the changes and the way you > > have it setup looks slick to me, not to mention well documented and > > maintainable. > > > > I am going to update and compile now. > > > > Great work! > > > > Sean > > > > On 5/21/07, Alex Fenton <alex at pressure.to> wrote: > > > Hi > > > > > > Just a quick update on memory leaks etc. I''ve just dropped a bunch of > > > patches with a new approach to linking ruby''s GC to Wx''s memory > > > handling. Still some work to do - eg bigdemo.rb falls over quite quickly > > > - but working well for me on other samples. > > > > > > Briefly, it disposes of fixdeleting. For almost all objects that aren''t > > > Windows, they should now be deleted when the ruby object has fallen out > > > of scope and garbage collection is done. This is normal SWIG behaviour. > > > So this should address memory leaks eg with Wx::Bitmap. > > > > > > Windows are a bit different, as they may not be referenced by any ruby > > > variable, but still very much alive displayed on the screen. The > > > instance of Wx::App now listens for all notifications of windows being > > > destroyed from WxWidgets (via wxWindowDestroyEvent). In ruby''s GC mark > > > phase, all known SWIG objects are checked, and if they point to a Window > > > that hasn''t yet been destroyed, they are marked to prevent them being > > > destroyed. > > > > > > Anyway, apologies if you find things a bit shaky for a little while - > > > shout with other samples you find to be crashing. But should be worth it > > > to fix wxRuby''s bad memory habits, and more maintainable too. > > > > > > alex > > > > > > > > > _______________________________________________ > > > Wxruby-development mailing list > > > Wxruby-development at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/wxruby-development > > > > > >
Alex Fenton
2007-May-22 08:24 UTC
[Wxruby-development] First drop of new memory management
Sean Long wrote:> The first problem I have found is with resizing windows, it crashes > with multiple samples. > > Here is the output of the printing sample when running ruby in debug mode >Thanks for the report. I''ve added two patches which seem to fix the printing sample and some others. Let me know what''s still not working as there''s some variation across platforms (eg I''ve been working on Linux and it didn''t have the printing crasher, but did get it on OS X). Incidentally, will also try and fix those __wx_destroyed__ uninitialized warnings under debug. cheers alex
Alex, Those changes made a difference but we still have some issues. Here is my WxRuby sample status after applying those last commits: Found problems in samples In AUI: - Trying to resize the window crashes the app. In Bigdemo: - Trying to resize the window crashes the app. - Trying to move the window crashes the app. In Caret: - Trying to resize the window crashes the app, but only after on GC mark phase has already happened. In Controls: - Crashes on exit. In etc/choice: - Does not start, get error: choice.rb:26:in `append'': No matching function for overloaded ''wxChoice_Append'' (ArgumentError) In etc/miniframe: - Trying to resize the mini frame crashes the app. In etc/system_settings: - Trying to resize the window crashes the app, but only after on GC mark phase has already happened In grid: - Trying to resize the window crashes the app, but only after on GC mark phase has already happened In html: - Trying to resize the window crashes the app, but only after on GC mark phase has already happened In listbook: - Works fine but shows this message on exit: OnExit... listbook.rb:183:in `filter_event'': in method ''FilterEvent'', argument 1 of type ''wxRubyApp *'' (ObjectPreviouslyDeleted) from listbook.rb:183:in `main_loop'' from listbook.rb:183 In printing: - Works fine until trying to print then we get: (this error was there before the memory cleanup code) printing.rb:268:in `draw_page_one'': undefined method `/'' for #<Wx::Size: (2400, 3058)> (NoMethodError) from printing.rb:211:in `on_print_page'' from printing.rb:137:in `print'' from printing.rb:137:in `on_print'' from printing.rb:33:in `initialize'' from printing.rb:480:in `call'' from printing.rb:480:in `process_event'' from printing.rb:480:in `main_loop'' from printing.rb:480 In text/unicode: - Works fine up until invoking the about menu, then we get: unicode.rb:224:in `on_about'': undefined method `message_box'' for #<IConvFrame:0x107d5b8> (NoMethodError) from unicode.rb:183:in `construct_menus'' from unicode.rb:238:in `call'' from unicode.rb:238:in `process_event'' from unicode.rb:238:in `main_loop'' from unicode.rb:238 In treectrl: - Trying to resize the window crashes the app, but only after on GC mark phase has already happened Samples that seem ok: - Dialogs - etc/activation - etc/sash - etc/scrollwin - etc/wizard - images - mdi (not like it does much on OS X) - minimal/minimal - minimal/nothing - minimal/text - text/scintilla (could not test, do not have scintilla installed) - text/textctrl - xrc Sean On 5/22/07, Alex Fenton <alex at pressure.to> wrote:> Sean Long wrote: > > The first problem I have found is with resizing windows, it crashes > > with multiple samples. > > > > Here is the output of the printing sample when running ruby in debug mode > > > > Thanks for the report. I''ve added two patches which seem to fix the > printing sample and some others. Let me know what''s still not working as > there''s some variation across platforms (eg I''ve been working on Linux > and it didn''t have the printing crasher, but did get it on OS X). > > Incidentally, will also try and fix those __wx_destroyed__ uninitialized > warnings under debug. > > cheers > alex > _______________________________________________ > Wxruby-development mailing list > Wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >
Sean Long wrote:> Alex, > > Those changes made a difference but we still have some issues. Here is > my WxRuby sample status after applying those last commits: >This is really helpful. Quite a lot of crash-on-resize ones came down to GC cleaning up Sizers when still in use. Still some work to do on nested sizers, and on events (b/c GC can start in the middle of processing), but making progress a
How are you debugging these problems so quickly, are you using a special ruby debugger or something I don''t know about? Thanks Sean On 5/22/07, Alex Fenton <alex at pressure.to> wrote:> Sean Long wrote: > > Alex, > > > > Those changes made a difference but we still have some issues. Here is > > my WxRuby sample status after applying those last commits: > > > This is really helpful. Quite a lot of crash-on-resize ones came down to > GC cleaning up Sizers when still in use. Still some work to do on nested > sizers, and on events (b/c GC can start in the middle of processing), > but making progress > > a > _______________________________________________ > Wxruby-development mailing list > Wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >
The last commit fixed the following samples: - Caret - etc/miniframe - etc/system_settings sean On 5/22/07, Sean Long <sean.m.long at gmail.com> wrote:> How are you debugging these problems so quickly, are you using a > special ruby debugger or something I don''t know about? > > Thanks > > Sean > > On 5/22/07, Alex Fenton <alex at pressure.to> wrote: > > Sean Long wrote: > > > Alex, > > > > > > Those changes made a difference but we still have some issues. Here is > > > my WxRuby sample status after applying those last commits: > > > > > This is really helpful. Quite a lot of crash-on-resize ones came down to > > GC cleaning up Sizers when still in use. Still some work to do on nested > > sizers, and on events (b/c GC can start in the middle of processing), > > but making progress > > > > a > > _______________________________________________ > > Wxruby-development mailing list > > Wxruby-development at rubyforge.org > > http://rubyforge.org/mailman/listinfo/wxruby-development > > >
Sean Long wrote:> How are you debugging these problems so quickly, are you using a > special ruby debugger or something I don''t know about? > >I''m using gdb. On OS X and Linux I run the sample like this (assuming you''re in the base wxruby2 directory) gdb --args ruby -Ilib samples/minimal/minimal.rb This''ll bring up a gdb prompt. Type ''r'' to run the sample. When it crashes the sample will freeze, rather than exit, and the gdb prompt will come back. I type ''where'' to get a backtrace. It''s pretty long but usually the relevant frame is in the first fifteen or twenty frames. When the crashes arise in the wx API functions, it usually means a C++ object has got deleted too early. When the crashes come in rb_funcall in a SWIG_Director, it usually means a ruby object has got deleted too early. a
Thanks that will be helpful Sean On 5/22/07, Alex Fenton <alex at pressure.to> wrote:> Sean Long wrote: > > How are you debugging these problems so quickly, are you using a > > special ruby debugger or something I don''t know about? > > > > > I''m using gdb. On OS X and Linux I run the sample like this (assuming > you''re in the base wxruby2 directory) > > gdb --args ruby -Ilib samples/minimal/minimal.rb > > This''ll bring up a gdb prompt. Type ''r'' to run the sample. When it > crashes the sample will freeze, rather than exit, and the gdb prompt > will come back. I type ''where'' to get a backtrace. It''s pretty long but > usually the relevant frame is in the first fifteen or twenty frames. > > When the crashes arise in the wx API functions, it usually means a C++ > object has got deleted too early. When the crashes come in rb_funcall in > a SWIG_Director, it usually means a ruby object has got deleted too early. > > a > _______________________________________________ > Wxruby-development mailing list > Wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >
Alex, The last few commits fixed a few more problems with the samples. The following still have memory related problems. In AUI: - Trying to resize the window crashes the app. - Also getting: No event class defined for event type 10090 In treectrl: - Trying to resize the window crashes the app, but only after on GC mark phase has already happened Excellent work BTW Sean On 5/23/07, Sean Long <sean.m.long at gmail.com> wrote:> Thanks that will be helpful > > Sean > > On 5/22/07, Alex Fenton <alex at pressure.to> wrote: > > Sean Long wrote: > > > How are you debugging these problems so quickly, are you using a > > > special ruby debugger or something I don''t know about? > > > > > > > > I''m using gdb. On OS X and Linux I run the sample like this (assuming > > you''re in the base wxruby2 directory) > > > > gdb --args ruby -Ilib samples/minimal/minimal.rb > > > > This''ll bring up a gdb prompt. Type ''r'' to run the sample. When it > > crashes the sample will freeze, rather than exit, and the gdb prompt > > will come back. I type ''where'' to get a backtrace. It''s pretty long but > > usually the relevant frame is in the first fifteen or twenty frames. > > > > When the crashes arise in the wx API functions, it usually means a C++ > > object has got deleted too early. When the crashes come in rb_funcall in > > a SWIG_Director, it usually means a ruby object has got deleted too early. > > > > a > > _______________________________________________ > > Wxruby-development mailing list > > Wxruby-development at rubyforge.org > > http://rubyforge.org/mailman/listinfo/wxruby-development > > >
Hi Sean Thanks for the update. I think we''re getting there... Sean Long wrote:> In AUI: > - Trying to resize the window crashes the app. > - Also getting: No event class defined for event type 10090 >Not sure what''s going on here. Will look into it. I overhauled the event handling system to make it a bit easier to manage, but it will probably show up a few event classes that we''ve missed on the way.> In treectrl: > - Trying to resize the window crashes the app, but only after on GC > mark phase has already happened > >Pretty sure this is down to a Wx::ImageList not being marked properly - hopefully will have patch for this shortly. cheers alex
As of commit 1051 the AUI and Treectrl sample are now working. The problem must have been the treectrl code in each sample. Sean On 6/4/07, Alex Fenton <alex at pressure.to> wrote:> Hi Sean > > Thanks for the update. I think we''re getting there... > > Sean Long wrote: > > In AUI: > > - Trying to resize the window crashes the app. > > - Also getting: No event class defined for event type 10090 > > > Not sure what''s going on here. Will look into it. I overhauled the event > handling system to make it a bit easier to manage, but it will probably > show up a few event classes that we''ve missed on the way. > > In treectrl: > > - Trying to resize the window crashes the app, but only after on GC > > mark phase has already happened > > > > > Pretty sure this is down to a Wx::ImageList not being marked properly - > hopefully will have patch for this shortly. > > cheers > alex > > _______________________________________________ > Wxruby-development mailing list > Wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >