From: Detlef R. <det...@gm...> - 2014-05-05 17:49:20
|
Hi kou, over the day at work I came to the same solution :-). Thank you! I've looked into the gtk+ sources. The implementation is not that nice, cause it takes a pointer of int as argument for the new order. So checking the data for doubles like it happened in my example is useless, cause even the length of the list can't be checked. To get the safety for my programs I've extended the ListStore class in the following way. It checked if the order index has the same size as the list and if the indices are valid. module Gtk class ListStore alias_method :old_reorder, :reorder def reorder order self_length = 0 self.each {self_length += 1} raise ArgumentError, "invalid new_order size" unless self_length == order.length new_order = order.sort.uniq raise ArgumentError, "invalid index in new_order" if (new_order.length() != order.length() or new_order.last != order.length() -1) old_reorder order end end end Is it worth to include it in ruby gtk? It think an thrown exception is always better then a program that eats all your memory and CPU time and then crashes without a useful message. Cheers detlef Am 05.05.2014 08:11, schrieb Kouhei Sutou: > Hi, > > In <536...@gm...> > "[ruby-gnome2-devel-en] Next memory leak and infinity loop" on Sun, 04 May 2014 19:45:19 +0200, > Detlef Reichl <det...@gm...> wrote: > >> I've stumbled over the next bug. If I use the Gtk::ListStore.reorder >> method the memory get filled up and the program hangs. Here is a short >> example. Start it and click on "memory pig :-)". Take care, it eats all >> your memory _very_ fast! > It seems that your program uses reorder wrongly. Try the > following code: > > active = [] > inactive = [] > i = 0 > @tvListStore.each do |model, path, iter| > if iter[1] > active << i > else > inactive << i > end > i += 1 > end > @tvListStore.reorder(active + inactive) > > Thanks, > -- > kou > > ------------------------------------------------------------------------------ > Is your legacy SCM system holding you back? Join Perforce May 7 to find out: > • 3 signs your SCM is hindering your productivity > • Requirements for releasing software faster > • Expert tips and advice for migrating your SCM now > http://p.sf.net/sfu/perforce > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > |