From: "shyouhei (Shyouhei Urabe)" Date: 2012-06-27T18:33:00+09:00 Subject: [ruby-core:45912] [ruby-trunk - Bug #6614] GC doesn't collect objects bound to (collectable) proc Issue #6614 has been updated by shyouhei (Shyouhei Urabe). cjheath (Clifford Heath) wrote: > On 27/06/2012, at 4:35 PM, nobu (Nobuyoshi Nakada) wrote: > > headius (Charles Nutter) wrote: > >> Finalizers in JRuby are stored on a reference from the object itself, so they don't actually prevent the object from collecting. > > > > You're missing the point. > > Is he? Surely somewhere in that loop{finalized_puts []} the GC will activate, > and that will find collectable objects (with finalisers attached in JRuby). In > MRI, they might be found but they won't be finalised, if I understand the > behaviour right. When a proc that touches an object is attatched to that object's finalizer, that finalizer can "escape" that object. ObjectSpace.define_finalizer(obj) { $escaped = obj } # Woo! This would break the whole concept of finalizing. Nobu's point is that how JRuby prevents this situation. ---------------------------------------- Bug #6614: GC doesn't collect objects bound to (collectable) proc https://bugs.ruby-lang.org/issues/6614#change-27518 Author: rogerdpack (Roger Pack) Status: Rejected Priority: Normal Assignee: Category: Target version: ruby -v: tcs-ruby 1.9.3p28 (2012-01-28, TCS patched 2012-01-30) [i386-mingw32] Hello all. Previously discussed here: http://www.ruby-forum.com/topic/4402823 I would expect the following code to eventually run the finalizers mentioned: def finalized_puts bad ObjectSpace.define_finalizer(bad) { print 'collector run', bad } end loop { finalized_puts [] } This works in jruby as expected, but not in MRI. This has the unfortunate side effect of making define_finalizer *very* difficult to actually use right http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/ Cheers! -- http://bugs.ruby-lang.org/