From: "Kroeger Simon (ext)" Date: 2005-08-11T00:16:10+09:00 Subject: Re: force_recycle > Hi, > > At Wed, 10 Aug 2005 23:48:00 +0900, > Kroeger Simon (ext) wrote in [ruby-talk:151506]: > > Ok, perhaps I (wanted to) misinterpret Nobu's 'no'. I thought this > > refers to the accessibility from within ruby. > > Sorry, I was too terse. > > The reason why it is not accessible from ruby is that it's too > dangerous; it can cause crash easily if it were possible. > > Consider: > > x = Foo.new > GC.force_recycle(x) > x.inspect > > Accessing recycled object would raise "terminated object" > exception if you're lucky. > > -- > Nobu Nakada :) I'm not lucky, but that's ok. I have a rather large project here and it is eating memory. I thought it would be nice to delete the objects we think are obsolet and see where it goes down. I wrote an extension do be able to access rb_gc_force_recycle. Here is my test: ------------------------------------------------- require 'force_recycle' class A def a return 'foo' end end $stdin.sync = true a = A.new b = A.new puts a.a ObjectSpace.each_object(A){|o| p o} force_recycle(a) GC.start puts 'After GC' ObjectSpace.each_object(A){|o| p o} puts a.a # BOOOOM ------------------------------------------------- and the output: ------------------------------------------------- foo # # After GC # This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. ------------------------------------------------- I would have been realy happy if I got the exception (and the traceback). So I have to think about another way... Simon