Question

I'm working on an app that downloads resources and writes them to disk for later offline use and it's always custom content. Currently we're working with content where there are about 4000 JPGs. The user initializes the download of the content onto the iPad and there's a progress bar in the UI, so the user does basically wait until it's done. Problem is that around 180 - 190 MB of memory allocated, it crashes.

What I've seen in Instruments is that CFData (store) is the main culprit and my understanding is that CFData (store) is the cache for NSURLConnection requests.

I've tried:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];

and

[[NSURLCache sharedURLCache] removeAllCachedResponses];

as well as setting the Cache policy, to no improvement.

For reference, this is what my post request looks like:

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSString *contentType = [NSString stringWithFormat:@"text/xml"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"]; 

NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[xmlMessage dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postBody];

//get response
NSHTTPURLResponse* urlResponse = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&httpError];

Any help would be met with great applause.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top