https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112012-06-21T09:33:23ZRuby Issue Tracking SystemRuby master - Bug #6614: GC doesn't collect objects bound to (collectable) prochttps://redmine.ruby-lang.org/issues/6614?journal_id=273182012-06-21T09:33:23Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>=begin<br>
Finalizers will run ((<em>AFTER</em>)) the target object has been destroyed and collected, so finalizers ((<em>MUST NOT</em>)) refer the object.<br>
I'm not certain why it is called in JRuby, but suspect it might be optimized out?<br>
=end</p> Ruby master - Bug #6614: GC doesn't collect objects bound to (collectable) prochttps://redmine.ruby-lang.org/issues/6614?journal_id=273202012-06-21T10:03:24Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
A correction.</p>
<p>Your code uses (({print})) but not (({printf})), so the arguments cannot be optimized out, even if necessary assumptions are all met.<br>
A possibility would be JRuby calls finalizers ((<em>BEFORE</em>)) the destruction.<br>
What's printed in JRuby?<br>
=end</p> Ruby master - Bug #6614: GC doesn't collect objects bound to (collectable) prochttps://redmine.ruby-lang.org/issues/6614?journal_id=274892012-06-27T02:23:19ZAnonymous
<ul></ul><blockquote>
<p>Your code uses <code>print' but not </code>printf', so the arguments cannot be optimized out, even if necessary assumptions are all met.<br>
A possibility would be JRuby calls finalizers <em>BEFORE</em> the destruction.<br>
What's printed in JRuby?</p>
</blockquote>
<p>runcollector runcollector</p>
<p>so it still has a reference to the old object. Which way seems more<br>
sane somehow, but is probably wrong.</p>
<p>I suppose my gripe is more that define_finalizer too many times<br>
creates proc's that are essentially "orphaned" but cannot be<br>
collected, which is basically a memory leak waiting to happen.<br>
Cheers!<br>
-r</p> Ruby master - Bug #6614: GC doesn't collect objects bound to (collectable) prochttps://redmine.ruby-lang.org/issues/6614?journal_id=275122012-06-27T14:03:18Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>Finalizers in JRuby are stored on a reference from the object itself, so they don't actually prevent the object from collecting.</p>
<p>I'd vote for MRI to do the same, but I don't think I'll win that fight :)</p> Ruby master - Bug #6614: GC doesn't collect objects bound to (collectable) prochttps://redmine.ruby-lang.org/issues/6614?journal_id=275132012-06-27T15:35:55Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>headius (Charles Nutter) wrote:</p>
<blockquote>
<p>Finalizers in JRuby are stored on a reference from the object itself, so they don't actually prevent the object from collecting.</p>
</blockquote>
<p>You're missing the point.</p> Ruby master - Bug #6614: GC doesn't collect objects bound to (collectable) prochttps://redmine.ruby-lang.org/issues/6614?journal_id=275162012-06-27T17:23:15Zcjheath (Clifford Heath)clifford.heath@gmail.com
<ul></ul><p>On 27/06/2012, at 4:35 PM, nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>headius (Charles Nutter) wrote:</p>
<blockquote>
<p>Finalizers in JRuby are stored on a reference from the object itself, so they don't actually prevent the object from collecting.</p>
</blockquote>
<p>You're missing the point.</p>
</blockquote>
<p>Is he? Surely somewhere in that loop{finalized_puts []} the GC will activate,<br>
and that will find collectable objects (with finalisers attached in JRuby). In<br>
MRI, they might be found but they won't be finalised, if I understand the<br>
behaviour right.</p>
<p>Clifford Heath.</p>
<blockquote>
<hr>
<p>Bug <a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: GC doesn't collect objects bound to (collectable) proc (Rejected)" href="https://redmine.ruby-lang.org/issues/6614">#6614</a>: GC doesn't collect objects bound to (collectable) proc<br>
<a href="https://bugs.ruby-lang.org/issues/6614#change-27513" class="external">https://bugs.ruby-lang.org/issues/6614#change-27513</a></p>
<p>Author: rogerdpack (Roger Pack)<br>
Status: Rejected<br>
Priority: Normal<br>
Assignee:<br>
Category:<br>
Target version:<br>
ruby -v: tcs-ruby 1.9.3p28 (2012-01-28, TCS patched 2012-01-30) [i386-mingw32]</p>
<p>Hello all.<br>
Previously discussed here: <a href="http://www.ruby-forum.com/topic/4402823" class="external">http://www.ruby-forum.com/topic/4402823</a></p>
<p>I would expect the following code to eventually run the finalizers mentioned:</p>
<p>def finalized_puts bad<br>
ObjectSpace.define_finalizer(bad) { print 'collector run', bad }<br>
end</p>
<p>loop { finalized_puts [] }</p>
<p>This works in jruby as expected, but not in MRI. This has the unfortunate side effect of making define_finalizer <em>very</em> difficult to actually use right <a href="http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/" class="external">http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/</a></p>
<p>Cheers!</p>
<p>--<br>
<a href="http://bugs.ruby-lang.org/" class="external">http://bugs.ruby-lang.org/</a></p>
</blockquote> Ruby master - Bug #6614: GC doesn't collect objects bound to (collectable) prochttps://redmine.ruby-lang.org/issues/6614?journal_id=275182012-06-27T18:32:57Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>cjheath (Clifford Heath) wrote:</p>
<blockquote>
<p>On 27/06/2012, at 4:35 PM, nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>headius (Charles Nutter) wrote:</p>
<blockquote>
<p>Finalizers in JRuby are stored on a reference from the object itself, so they don't actually prevent the object from collecting.</p>
</blockquote>
<p>You're missing the point.</p>
</blockquote>
<p>Is he? Surely somewhere in that loop{finalized_puts []} the GC will activate,<br>
and that will find collectable objects (with finalisers attached in JRuby). In<br>
MRI, they might be found but they won't be finalised, if I understand the<br>
behaviour right.</p>
</blockquote>
<p>When a proc that touches an object is attatched to that object's finalizer, that finalizer can "escape" that object.</p>
<p>ObjectSpace.define_finalizer(obj) { $escaped = obj } # Woo!</p>
<p>This would break the whole concept of finalizing. Nobu's point is that how JRuby prevents this situation.</p> Ruby master - Bug #6614: GC doesn't collect objects bound to (collectable) prochttps://redmine.ruby-lang.org/issues/6614?journal_id=275452012-06-28T17:29:35Zfunny_falcon (Yura Sokolov)funny.falcon@gmail.com
<ul></ul><p>It seems that ObjectSpace.define_finalizer is complitely broken with Ruby 1.9.3<br>
And even in Ruby 1.8.7 finalizer proc ought to be created in other scope to not hold reference to object in its binding.<br>
See <a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: Object finalizer do not run until program exit (Rejected)" href="https://redmine.ruby-lang.org/issues/6664">#6664</a> and <a href="https://gist.github.com/3009867" class="external">https://gist.github.com/3009867</a> for more</p>