<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The Trouble with Ruby Finalizers</title>
	<atom:link href="http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/</link>
	<description>On Ruby, software and the Internet</description>
	<lastBuildDate>Tue, 07 Feb 2012 17:12:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Ed Schmalzle &#187; Blog Archive &#187; TIL Ruby ObjectSpace#define_finalizer</title>
		<link>http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/comment-page-1/#comment-1336</link>
		<dc:creator>Ed Schmalzle &#187; Blog Archive &#187; TIL Ruby ObjectSpace#define_finalizer</dc:creator>
		<pubDate>Thu, 19 Jan 2012 22:59:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/?p=380#comment-1336</guid>
		<description>[...] This got me wondering: &#8220;does Ruby have finalizers?&#8221;. It turns out it does in the form of ObjectSpace#define_finalizer. It&#8217;s worth mentioning that there are some tricks to using them which are nicely documented on Mike Perham&#8217;s blog here. [...]</description>
		<content:encoded><![CDATA[<p>[...] This got me wondering: &#8220;does Ruby have finalizers?&#8221;. It turns out it does in the form of ObjectSpace#define_finalizer. It&#8217;s worth mentioning that there are some tricks to using them which are nicely documented on Mike Perham&#8217;s blog here. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William Taysom</title>
		<link>http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/comment-page-1/#comment-1318</link>
		<dc:creator>William Taysom</dc:creator>
		<pubDate>Tue, 03 Jan 2012 09:53:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/?p=380#comment-1318</guid>
		<description>Subtle and evil indeed!  Thank you for the post.  It saved us from a world of hurt.</description>
		<content:encoded><![CDATA[<p>Subtle and evil indeed!  Thank you for the post.  It saved us from a world of hurt.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Perham</title>
		<link>http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/comment-page-1/#comment-715</link>
		<dc:creator>Mike Perham</dc:creator>
		<pubDate>Wed, 18 Aug 2010 15:07:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/?p=380#comment-715</guid>
		<description>Jamie, I&#039;ve fixed the typo.  You want it to call finalize; that method returns the actual proc that will be called to finalize the object.

If you want access to the member variables, you have to pass them into the finalize() method so they are available to the finalizer, just like the name variable.</description>
		<content:encoded><![CDATA[<p>Jamie, I&#8217;ve fixed the typo.  You want it to call finalize; that method returns the actual proc that will be called to finalize the object.</p>
<p>If you want access to the member variables, you have to pass them into the finalize() method so they are available to the finalizer, just like the name variable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Cook</title>
		<link>http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/comment-page-1/#comment-714</link>
		<dc:creator>Jamie Cook</dc:creator>
		<pubDate>Wed, 18 Aug 2010 14:39:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/?p=380#comment-714</guid>
		<description>Hey, i&#039;m tying to figure out finalizers and came across this post but can&#039;t get your example to work. There is a extraneous right curly brace in the line 

ObjectSpace.define_finalizer( self, self.class.finalize(name) } )

and even after I remove that, the syntax doesn&#039;t define a callable method. Instead it just calls the method :) 

You can wrap it in a Proc 

ObjectSpace.define_finalizer(self,proc{&#124;id&#124; self.class.finalize(name)})

but that creates a closure which binds self, preventing the object from being garbage collected! 

How on earth are you meant to get access to the member variables from a finaliser?</description>
		<content:encoded><![CDATA[<p>Hey, i&#8217;m tying to figure out finalizers and came across this post but can&#8217;t get your example to work. There is a extraneous right curly brace in the line </p>
<p>ObjectSpace.define_finalizer( self, self.class.finalize(name) } )</p>
<p>and even after I remove that, the syntax doesn&#8217;t define a callable method. Instead it just calls the method <img src='http://www.mikeperham.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>You can wrap it in a Proc </p>
<p>ObjectSpace.define_finalizer(self,proc{|id| self.class.finalize(name)})</p>
<p>but that creates a closure which binds self, preventing the object from being garbage collected! </p>
<p>How on earth are you meant to get access to the member variables from a finaliser?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Delicious Bookmarks for March 25th from 14:22 to 16:56 &#171; Lâmôlabs</title>
		<link>http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/comment-page-1/#comment-526</link>
		<dc:creator>Delicious Bookmarks for March 25th from 14:22 to 16:56 &#171; Lâmôlabs</dc:creator>
		<pubDate>Thu, 25 Mar 2010 21:16:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/?p=380#comment-526</guid>
		<description>[...] The Trouble with Ruby Finalizers &#8211; March 25th  %(postalicious-tags)( tags: ruby bugs programming finalizer gc leak memory garbage collection )% [...]</description>
		<content:encoded><![CDATA[<p>[...] The Trouble with Ruby Finalizers &#8211; March 25th  %(postalicious-tags)( tags: ruby bugs programming finalizer gc leak memory garbage collection )% [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Labnotes &#187; Rounded Corners 249 — Life before Google</title>
		<link>http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/comment-page-1/#comment-486</link>
		<dc:creator>Labnotes &#187; Rounded Corners 249 — Life before Google</dc:creator>
		<pubDate>Mon, 01 Mar 2010 16:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/?p=380#comment-486</guid>
		<description>[...] How to forget. On the common mistake of finalizing with a closure reference. [...]</description>
		<content:encoded><![CDATA[<p>[...] How to forget. On the common mistake of finalizing with a closure reference. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Evan Phoenix</title>
		<link>http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/comment-page-1/#comment-484</link>
		<dc:creator>Evan Phoenix</dc:creator>
		<pubDate>Mon, 01 Mar 2010 07:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikeperham.com/?p=380#comment-484</guid>
		<description>Agreed. The OS#define_finalizer API sadly invites this exact bug. Pretty much everyone who has even used OS#define_finalizer has hit this bug. Some catch it right away, but lots don&#039;t.

The API invites this bug because there the object isn&#039;t passed to the block, and thusly people think they want the object to be in the closure to they can do something with it when it&#039;s being finalized. Ruby&#039;s GC can&#039;t deal with this, and thus the passing of #object_id to the block.

In Rubinius, I&#039;m working on adding true finalizers: code that runs when an object was just detected as garbage, but can access the object itself. The finalizer code can even resurrect the object and it will be finalized later. Not yet sure what the API for this will be (a #finalize method on the object maybe?) but it should help in some ways.</description>
		<content:encoded><![CDATA[<p>Agreed. The OS#define_finalizer API sadly invites this exact bug. Pretty much everyone who has even used OS#define_finalizer has hit this bug. Some catch it right away, but lots don&#8217;t.</p>
<p>The API invites this bug because there the object isn&#8217;t passed to the block, and thusly people think they want the object to be in the closure to they can do something with it when it&#8217;s being finalized. Ruby&#8217;s GC can&#8217;t deal with this, and thus the passing of #object_id to the block.</p>
<p>In Rubinius, I&#8217;m working on adding true finalizers: code that runs when an object was just detected as garbage, but can access the object itself. The finalizer code can even resurrect the object and it will be finalized later. Not yet sure what the API for this will be (a #finalize method on the object maybe?) but it should help in some ways.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

