nobody at rubyforge.org
2007-Jun-01 16:21 UTC
[Wxruby-development] [1044] trunk/wxruby2: Special memory management for Wx::Grid
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:'':'';} #msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1044] trunk/wxruby2: Special memory management for Wx::Grid</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1044</dd> <dt>Author</dt> <dd>brokentoy</dd> <dt>Date</dt> <dd>2007-06-01 12:21:13 -0400 (Fri, 01 Jun 2007)</dd> </dl> <h3>Log Message</h3> <pre>Special memory management for Wx::Grid</pre> <h3>Modified Paths</h3> <ul> <li><a href="#trunkwxruby2swigclassesGridi">trunk/wxruby2/swig/classes/Grid.i</a></li> </ul> <h3>Added Paths</h3> <ul> <li><a href="#trunkwxruby2libwxclassesgridrb">trunk/wxruby2/lib/wx/classes/grid.rb</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="trunkwxruby2libwxclassesgridrb"></a> <div class="addfile"><h4>Added: trunk/wxruby2/lib/wx/classes/grid.rb (0 => 1044)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/lib/wx/classes/grid.rb         (rev 0) +++ trunk/wxruby2/lib/wx/classes/grid.rb        2007-06-01 16:21:13 UTC (rev 1044) </span><span class="lines">@@ -0,0 +1,52 @@ </span><ins>+# A data-oriented editable table control. +class Wx::Grid + # The following extensions are all to prevent crashes associated with + # garbage collection of Grid-related classes; they do not extend the + # public functionality of the class in any way. + # + # The GridCellRenderers and GridCellEditors pose a problem for ruby''s + # GC, in that Wx makes them owned by the grid once they have been set + # for a cell or group of cells. However, because they are SWIG + # directors we cannot allow the ruby object they are originally + # associated with to be swept by GC. + # + # So we keep track of editors and renderers that have been set for + # particular cells or as the default within hashes that are instance + # variables of the Grid object. This means that as long as the Grid is + # not garbage collected, the associated renderers will be marked in + # the GC mark phase and so preserved. + # + # For most classes we handle GC on the SWIG side but honestly it''d be + # a whole lot more messy coding... + wx_init = self.instance_method(:initialize) + define_method(:initialize) do | *args | + wx_init.bind(self).call(*args) + + @__renderers = {} + @__editors = {} + end + + wx_set_cell_renderer = self.instance_method(:set_cell_renderer) + define_method(:set_cell_renderer) do | row, col, rendr | + wx_set_cell_renderer.bind(self).call(row, col, rendr) + @__renderers[ [row, col] ] = rendr + end + + wx_set_default_renderer = self.instance_method(:set_default_renderer) + define_method(:set_default_renderer) do | rendr | + wx_set_default_renderer.bind(self).call(rendr) + @__renderers[ nil ] = rendr + end + + wx_set_cell_editor = self.instance_method(:set_cell_editor) + define_method(:set_cell_editor) do | row, col, editr | + wx_set_cell_editor.bind(self).call(row, col, editr) + @__editors[ [row, col] ] = editr + end + + wx_set_default_editor = self.instance_method(:set_default_editor) + define_method(:set_default_editor) do | editr | + wx_set_default_editor.bind(self).call(editr) + @__editors[ nil ] = editr + end +end </ins></span></pre></div> <a id="trunkwxruby2swigclassesGridi"></a> <div class="modfile"><h4>Modified: trunk/wxruby2/swig/classes/Grid.i (1043 => 1044)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/swig/classes/Grid.i        2007-05-31 21:20:41 UTC (rev 1043) +++ trunk/wxruby2/swig/classes/Grid.i        2007-06-01 16:21:13 UTC (rev 1044) </span><span class="lines">@@ -10,6 +10,10 @@ </span><span class="cx"> #include <wx/grid.h> </span><span class="cx"> %} </span><span class="cx"> </span><ins>+ +// Memory management is needed for these classes in addition to *DISOWN +// to prevent premature ruby GC. To save a lot of messy C++ The work is +// done in pure ruby - see lib/wx/classes/grid.rb </ins><span class="cx"> %apply SWIGTYPE *DISOWN { wxGridCellAttr* attr }; </span><span class="cx"> %apply SWIGTYPE *DISOWN { wxGridCellEditor* editor }; </span><span class="cx"> %apply SWIGTYPE *DISOWN { wxGridCellRenderer* renderer }; </span></span></pre> </div> </div> </body> </html>
Reasonably Related Threads
- [ANNOUNCE] editres 1.0.7
- [872] trunk/wxruby2/swig/classes/Grid.i: Prevent GC prematurely cleaning up Grid-related classes
- Fwd: [ mocha-Feature Requests-5856 ] Stubbing of private methods should be allowed
- [861] trunk/wxruby2/doc/textile/grid.txtl: Added missing methods listing section
- An unprofessional message