<?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: Don&#8217;t pass objects as context pointers</title>
	<atom:link href="http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/feed" rel="self" type="application/rss+xml" />
	<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers</link>
	<description>The personal weblog of Peter Hosey.</description>
	<lastBuildDate>Wed, 09 May 2012 18:26:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: BJ Homer</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-273785</link>
		<dc:creator>BJ Homer</dc:creator>
		<pubDate>Thu, 07 May 2009 02:51:42 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-273785</guid>
		<description>Nevermind that; it ends up being pretty much the same solution you already suggested.  You could just as easily pass the ivar in the context pointer; the sheet already has access to &lt;code&gt;self&lt;/code&gt; by virtue of being a delegate.</description>
		<content:encoded><![CDATA[<p>Nevermind that; it ends up being pretty much the same solution you already suggested.  You could just as easily pass the ivar in the context pointer; the sheet already has access to <code>self</code> by virtue of being a delegate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BJ Homer</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-273781</link>
		<dc:creator>BJ Homer</dc:creator>
		<pubDate>Thu, 07 May 2009 02:44:57 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-273781</guid>
		<description>What if you created an instance variable in &lt;code&gt;self&lt;/code&gt; to store the object and then pass &lt;code&gt;self&lt;/code&gt; in the context pointer?  The sheet can access the object through the context pointer, but doesn&#039;t need to retain it.  It&#039;s a weak pointer, and if &lt;code&gt;self&lt;/code&gt; goes away, the object isn&#039;t leaked.  In this case, the context pointer really does become more of a &lt;i&gt;context&lt;/i&gt; pointer.</description>
		<content:encoded><![CDATA[<p>What if you created an instance variable in <code>self</code> to store the object and then pass <code>self</code> in the context pointer?  The sheet can access the object through the context pointer, but doesn&#8217;t need to retain it.  It&#8217;s a weak pointer, and if <code>self</code> goes away, the object isn&#8217;t leaked.  In this case, the context pointer really does become more of a <i>context</i> pointer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-264838</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Mon, 06 Apr 2009 15:24:57 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-264838</guid>
		<description>Petteri Kamppuri: Yes, since &lt;code&gt;-retain&lt;/code&gt; and &lt;code&gt;-release&lt;/code&gt; are no-ops. This doesn&#039;t solve the problem that you&#039;re putting an object through the context pointer in the first place; all it is is retaining and releasing it in a different way. As I said in the post, everything I said there applies just as much with GC as without it.

I disagree with Apple&#039;s statement that “The solution is to use a &lt;code&gt;CFRetain&lt;/code&gt;/&lt;code&gt;CFRelease&lt;/code&gt; pair as the value is put into/taken out of the &lt;code&gt;void *&lt;/code&gt; parameter.” The solution is to hold your own strong reference to the object.</description>
		<content:encoded><![CDATA[<p>Petteri Kamppuri: Yes, since <code>-retain</code> and <code>-release</code> are no-ops. This doesn&#8217;t solve the problem that you&#8217;re putting an object through the context pointer in the first place; all it is is retaining and releasing it in a different way. As I said in the post, everything I said there applies just as much with GC as without it.</p>
<p>I disagree with Apple&#8217;s statement that “The solution is to use a <code>CFRetain</code>/<code>CFRelease</code> pair as the value is put into/taken out of the <code>void *</code> parameter.” The solution is to hold your own strong reference to the object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Petteri Kamppuri</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-264724</link>
		<dc:creator>Petteri Kamppuri</dc:creator>
		<pubDate>Mon, 06 Apr 2009 07:07:02 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-264724</guid>
		<description>It seems that Apple recommends the CFRetain/CFRelease solution, at least in a GC environment.

http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcUsing.html#//apple_ref/doc/uid/TP40008006-SW4</description>
		<content:encoded><![CDATA[<p>It seems that Apple recommends the CFRetain/CFRelease solution, at least in a GC environment.</p>
<p><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcUsing.html#//apple_ref/doc/uid/TP40008006-SW4" rel="nofollow">http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcUsing.html#//apple_ref/doc/uid/TP40008006-SW4</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-264036</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Sat, 04 Apr 2009 02:09:47 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-264036</guid>
		<description>Chuck: In this very post, I noted not one but two cases in which you leak the context object.</description>
		<content:encoded><![CDATA[<p>Chuck: In this very post, I noted not one but two cases in which you leak the context object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-263987</link>
		<dc:creator>Chuck</dc:creator>
		<pubDate>Fri, 03 Apr 2009 22:29:00 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-263987</guid>
		<description>This strikes me as unnecessarily introducing more code. As this pattern is normally used, I can&#039;t figure out what would lead to a memory leak. What is the situation where we gain any benefit except warm fuzzies from introducing ivars and setters and what-have-you?</description>
		<content:encoded><![CDATA[<p>This strikes me as unnecessarily introducing more code. As this pattern is normally used, I can&#8217;t figure out what would lead to a memory leak. What is the situation where we gain any benefit except warm fuzzies from introducing ivars and setters and what-have-you?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-263967</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Fri, 03 Apr 2009 20:02:27 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-263967</guid>
		<description>Jeff Johnson: Yeah, I saw that, too. Shouldn&#039;t be a problem as long as you only extend and not override.</description>
		<content:encoded><![CDATA[<p>Jeff Johnson: Yeah, I saw that, too. Shouldn&#8217;t be a problem as long as you only extend and not override.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Johnson</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-263966</link>
		<dc:creator>Jeff Johnson</dc:creator>
		<pubDate>Fri, 03 Apr 2009 19:40:21 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-263966</guid>
		<description>Peter, you&#039;re right, it appears not to be documented whether you can use endSheet: in that case. I&#039;ll see if I can find an example somewhere.

I did notice this in the documentation, however: &quot;The NSAlert class is not designed for subclassing.&quot;</description>
		<content:encoded><![CDATA[<p>Peter, you&#8217;re right, it appears not to be documented whether you can use endSheet: in that case. I&#8217;ll see if I can find an example somewhere.</p>
<p>I did notice this in the documentation, however: &#8220;The NSAlert class is not designed for subclassing.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-263958</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Fri, 03 Apr 2009 18:04:29 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-263958</guid>
		<description>Vincent Gable: If you&#039;re certain that there&#039;s no memory leak, then you can use the context pointer. But you&#039;re right that it&#039;s dubious even for non-objects—consider the case of something you&#039;ve mallocked, for example.

Jeff Johnson: Hm. I&#039;m not sure it&#039;s OK to pass NSAlert&#039;s window to &lt;code&gt;endSheet:returnCode:&lt;/code&gt;. The documentation doesn&#039;t say it is; all it says definitely is that you shouldn&#039;t use &lt;code&gt;orderOut:&lt;/code&gt; on the window from outside the did-end method.</description>
		<content:encoded><![CDATA[<p>Vincent Gable: If you&#8217;re certain that there&#8217;s no memory leak, then you can use the context pointer. But you&#8217;re right that it&#8217;s dubious even for non-objects—consider the case of something you&#8217;ve mallocked, for example.</p>
<p>Jeff Johnson: Hm. I&#8217;m not sure it&#8217;s OK to pass NSAlert&#8217;s window to <code>endSheet:returnCode:</code>. The documentation doesn&#8217;t say it is; all it says definitely is that you shouldn&#8217;t use <code>orderOut:</code> on the window from outside the did-end method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Johnson</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-263955</link>
		<dc:creator>Jeff Johnson</dc:creator>
		<pubDate>Fri, 03 Apr 2009 17:46:01 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-263955</guid>
		<description>I&#039;m not sure I understand point 3. Let&#039;s talk about NSAlert, because you really shouldn&#039;t be using NSBeginAlertSheet() anymore. ;-) If you called -[NSAlert beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:], and you&#039;re about to be deallocated, you should call -[NSApplication endSheet:returnCode:], in which case the didEndSelector is called.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure I understand point 3. Let&#8217;s talk about NSAlert, because you really shouldn&#8217;t be using NSBeginAlertSheet() anymore. ;-) If you called -[NSAlert beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:], and you&#8217;re about to be deallocated, you should call -[NSApplication endSheet:returnCode:], in which case the didEndSelector is called.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent Gable</title>
		<link>http://boredzo.org/blog/archives/2009-04-03/dont-pass-objects-as-context-pointers/comment-page-1#comment-263953</link>
		<dc:creator>Vincent Gable</dc:creator>
		<pubDate>Fri, 03 Apr 2009 17:37:06 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=976#comment-263953</guid>
		<description>By the same reasoning, is passing &lt;em&gt;anything&lt;/em&gt;, not just objects, to the context-pointer a bad idea, or are there cases where it&#039;s not a dirty thing to do?</description>
		<content:encoded><![CDATA[<p>By the same reasoning, is passing <em>anything</em>, not just objects, to the context-pointer a bad idea, or are there cases where it&#8217;s not a dirty thing to do?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.178 seconds -->

