<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>matthewjamesward.co.uk &#187; nsurlconnection</title>
	<atom:link href="http://matthewjamesward.co.uk/blog/tag/nsurlconnection/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewjamesward.co.uk/blog</link>
	<description></description>
	<lastBuildDate>Mon, 12 Sep 2011 09:35:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Solving NSURLConnection leaks</title>
		<link>http://matthewjamesward.co.uk/blog/2009/06/solving-nsurlconnection-leaks/</link>
		<comments>http://matthewjamesward.co.uk/blog/2009/06/solving-nsurlconnection-leaks/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 17:25:29 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[leak]]></category>
		<category><![CDATA[nsurlconnection]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://blog.fanattic.it/?p=65</guid>
		<description><![CDATA[Recently I was having a problem with NSURLConnection showing memory leaks in Instruments even though it was being correctly allocated and released. On investigation it seemed the problem may be lying with the cache policy, however I was using NSURLRequestReloadIgnoringLocalCacheData in the NSURLRequest to completely ignore any caching requirements and was confused as to why [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was having a problem with NSURLConnection showing memory leaks in <a title="Instruments (application)" href="http://en.wikipedia.org/wiki/Instruments_(application)" target="_blank">Instruments</a> even though it was being correctly allocated and released. On investigation it seemed the problem may be lying with the cache policy, however I was using NSURLRequestReloadIgnoringLocalCacheData in the NSURLRequest to completely ignore any caching requirements and was confused as to why allocation problems would then be associated with caching.</p>
<p>I&#8217;m still not exactly sure what the problem is (according to <a title="NSURLConnection leaking on multi-threaded apps?" href="http://archives.devshed.com/forums/bsd-93/nsurlconnection-leaking-on-multi-threaded-apps-2220129.html" target="_blank">this thread</a> it may be due to having the NSURLConnection run in a method that&#8217;s detached from the main thread) however, forceably setting the capacity of the URL cache before initiating the connection using the URL request seems to solve the problem. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLCache</span> sharedURLCache<span style="color: #002200;">&#93;</span> setMemoryCapacity<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLCache</span> sharedURLCache<span style="color: #002200;">&#93;</span> setDiskCapacity<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span>connection <span style="color: #002200;">=</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLConnection</span> alloc<span style="color: #002200;">&#93;</span> initWithRequest<span style="color: #002200;">:</span>request delegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Hey presto! No more NSURLConnection leaks.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewjamesward.co.uk/blog/2009/06/solving-nsurlconnection-leaks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

