<?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: Notes on Nib files and retaining IBOutlets</title>
	<atom:link href="http://www.greenwaysroad.com/blogs/vasuBlog/index.php/2011/01/16/notes-on-nib-files-and-retaining-iboutlets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.greenwaysroad.com/blogs/vasuBlog/index.php/2011/01/16/notes-on-nib-files-and-retaining-iboutlets/</link>
	<description></description>
	<lastBuildDate>Wed, 07 Nov 2012 21:50:51 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: mklement</title>
		<link>http://www.greenwaysroad.com/blogs/vasuBlog/index.php/2011/01/16/notes-on-nib-files-and-retaining-iboutlets/comment-page-1/#comment-3097</link>
		<dc:creator>mklement</dc:creator>
		<pubDate>Wed, 19 Jan 2011 21:23:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.greenwaysroad.com/blogs/vasuBlog/index.php/2011/01/16/notes-on-nib-files-and-retaining-iboutlets/#comment-3097</guid>
		<description>Thank you for that helpful article.

The following applies to the iOS world:
To avoid potential problems with calling methods or even property setters from the dealloc method you could try the following approach, which is based on preprocessor macros entirely - slightly inconvenient, but safer:

1. Define a macro that, given a flag and the name of a property, either calls the property setter to set the property to nil, or, based on a naming convention, releases - and sets to nil - the underlying ivar:

#define RELEASE_PROPERTY(useSetter, propName)	((useSetter) ? (self.propName = nil) : ([_##propName release], _##propName = nil))

Note that this macro relies on the naming convention of naming the ivar that backs a property the same as the property, prefixed with &quot;_&quot;.

2. In lieu of defining a releaseOutlets *method*, define a *macro* in each class that &#039;bundles&#039; all property-release statements, e.g.:

#define releaseOutlets(useSetters) \
	RELEASE_PROPERTY(useSetters, textField); \
	RELEASE_PROPERTY(useSetters, someOtherProperty); \ 
	RELEASE_PROPERTY(useSetters, yetAnotherProperty)

This is slightly inconvenient, in that each inner line must end in \ and in that you get no syntax coloring.

3. Call the macro 
-  from viewDidUnload:
	releaseOutlets(YES);
-  from dealloc:
	releaseOutlets(NO);
That way, no methods are called from the dealloc method. 

Finally, because it tripped me up is not obvious from the method names:
- viewDidUnload is ONLY called in LOW-MEMORY conditions.
- dealloc is typically NOT called when the  APPLICATION AS A WHOLE terminates.</description>
		<content:encoded><![CDATA[<p>Thank you for that helpful article.</p>
<p>The following applies to the iOS world:<br />
To avoid potential problems with calling methods or even property setters from the dealloc method you could try the following approach, which is based on preprocessor macros entirely &#8211; slightly inconvenient, but safer:</p>
<p>1. Define a macro that, given a flag and the name of a property, either calls the property setter to set the property to nil, or, based on a naming convention, releases &#8211; and sets to nil &#8211; the underlying ivar:</p>
<p>#define RELEASE_PROPERTY(useSetter, propName)	((useSetter) ? (self.propName = nil) : ([_##propName release], _##propName = nil))</p>
<p>Note that this macro relies on the naming convention of naming the ivar that backs a property the same as the property, prefixed with &#8220;_&#8221;.</p>
<p>2. In lieu of defining a releaseOutlets *method*, define a *macro* in each class that &#8216;bundles&#8217; all property-release statements, e.g.:</p>
<p>#define releaseOutlets(useSetters) \<br />
	RELEASE_PROPERTY(useSetters, textField); \<br />
	RELEASE_PROPERTY(useSetters, someOtherProperty); \<br />
	RELEASE_PROPERTY(useSetters, yetAnotherProperty)</p>
<p>This is slightly inconvenient, in that each inner line must end in \ and in that you get no syntax coloring.</p>
<p>3. Call the macro<br />
-  from viewDidUnload:<br />
	releaseOutlets(YES);<br />
-  from dealloc:<br />
	releaseOutlets(NO);<br />
That way, no methods are called from the dealloc method. </p>
<p>Finally, because it tripped me up is not obvious from the method names:<br />
- viewDidUnload is ONLY called in LOW-MEMORY conditions.<br />
- dealloc is typically NOT called when the  APPLICATION AS A WHOLE terminates.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
