From: ts Date: 2001-02-06T03:07:42+09:00 Subject: [ruby-talk:10378] Re: Problems creating persistent objects >>>>> "D" == Danny Sofer writes: D> 2) by the time the finalizer is called, all my instance variables seem to D> have disappeared, so i can't automatically store my data. any other D> suggestions? WARNING wait confirmation from matz It seems to work with this patch (this is another problem with 1.7 :-)) pigeon% diff -u gc.c.old gc.c --- gc.c.old Fri Dec 22 04:21:56 2000 +++ gc.c Mon Feb 5 18:51:29 2001 @@ -1227,7 +1227,7 @@ p = heaps[i]; pend = p + HEAP_SLOTS; while (p < pend) { if (FL_TEST(p, FL_FINALIZE)) { - p->as.free.flag = 0; + FL_UNSET(p, FL_FINALIZE); run_final((VALUE)p); } p++; pigeon% pigeon% cat b.rb module Storage def store print "should be storing #{@f}\n" File.open(@f, "w") { |f| Marshal.dump(@data, f) } end def retrieve File.open(@f) { |f| return Marshal.load(f) } end end class Obj include Storage def initialize(f, m='') @f = f puts "the file is #{@f}" @data = {} @data['m'] = '' if File.exists?(@f) @data = retrieve end puts "Old value : #{@data['m']}" @data['m'] = m puts "New value : #{@data['m']}" ObjectSpace.define_finalizer(self, proc { store } ) end end o = Obj.new('.test', 'hello') pigeon% pigeon% ruby b.rb the file is .test Old value : New value : hello should be storing .test pigeon% pigeon% ruby b.rb the file is .test Old value : hello New value : hello should be storing .test pigeon% Guy Decoux