Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I finally found the answer for this.</p> <p>The error in the above code (which by the way is the near-exact sample from the <a href="http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html" rel="noreferrer">SDK docs</a>) is not in the memory management code. Autorelease is one option, manual release is another. Regardless of how you handle your NSURLConnection object, you get leaks using NSURLConnection.</p> <p>First up, here is the solution. Just copy these 3 lines of code directly into connectionDidFinishLoading, didFailWithError and anywhere else you release the NSURLConnection object.</p> <pre><code>NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release]; </code></pre> <p>Credit to <em>mpramodjain</em> on <a href="http://forums.macrumors.com/showthread.php?t=573253" rel="noreferrer">http://forums.macrumors.com/showthread.php?t=573253</a> for the code.</p> <p>The problem seems to be this – the SDK caches the requests and replies on the iPhone. Even it seems if your NSMutableURLRequest cachePolicy is set to not load the reply from the cache.</p> <p>The silly thing is that it seems to cache a lot of data by default. I'm transmitting a lot of data (split into multiple connections) and started to get memory warnings, and finally my App died.</p> <p>The docs we need are in NSURLCache (not NSURLConnection), they state:</p> <blockquote> <p>NSURLCache implements the caching of responses to URL load requests by mapping NSURLRequest objects to NSCachedURLResponse objects. It is a composite of an in-memory and an on-disk cache.</p> <p>Methods are provided to manipulate the sizes of each of these caches as well as to control the path on disk to use for persistent storage of cache data.</p> </blockquote> <p>Those three lines have the effect of nuking the cache totally. After adding them to my App (<a href="http://gpslogapp.com" rel="noreferrer">GPS Log</a>), my #living object count remains steady.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload