On Sep 9, 2011, at 3:59 PM, David Duncan wrote: > On Sep 9, 2011, at 4:06 AM, Andreas Grosam wrote: > >> The problem I get with NSURLConnection is, that it internally uses a lot >> (really a lot) memory for its data buffers. It seems, the connection reads >> as much data as it can from the network and a tries to safe it in internal >> buffers, no matter what, apparently until the system cannot provide more >> memory. >> >> In a simple test app, NSURLConnections quite quickly consumes up to 10Mbyte >> for a number of its buffers - on the iPhone!, which is probably the maximum >> before the app will be killed. With Instruments, it can be viewed quite >> easily. > > > Try setting the memory size of the NSURLCache, something like [[NSURLCache > sharedURLCache] setMemoryCapacity:0]. > -- > David Duncan >
I already did this: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } and [[NSURLCache sharedURLCache] removeAllCachedResponses]; [[NSURLCache sharedURLCache] setMemoryCapacity:1024*64]; NSTimeInterval request_timeout = 600.0; NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:request_timeout]; Since I don't use a URL cache, I suspect the above cache settings are not in effect anyway. However, setting the timeout to a high value is crucial if the "processing" of data is slow, otherwise I get error -1001 (kCFURLErrorTimedOut) The problem seems really the buffers which will be used by NSURLConnection internally. They grow up to about 1 MBytes, and severals of them may be allocated. My app can be configured how many NSData buffers it keeps alive for processing in a FIFO queue and this is currently the minimum: just one (if more come in, the thread blocks). So, all other buffers should be freed sooner or later by NSURLConnection. But the huge sizes cause a problem on the tiny iPhone ;) and my code fights against NSURLConnection to get a share. One other thing is, using Instruments makes the scenario worse. When Instruments is connected, the app crashes much sooner due to memory problems. So, I support my observations on logs, too. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com