• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSURLConnection: "Greedy Memory Eater" and Error 303
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURLConnection: "Greedy Memory Eater" and Error 303


  • Subject: Re: NSURLConnection: "Greedy Memory Eater" and Error 303
  • From: Andreas Grosam <email@hidden>
  • Date: Fri, 09 Sep 2011 18:10:36 +0200

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSURLConnection: "Greedy Memory Eater" and Error 303
      • From: Jens Alfke <email@hidden>
    • Re: NSURLConnection: "Greedy Memory Eater" and Error 303
      • From: Andreas Grosam <email@hidden>
References: 
 >NSURLConnection: "Greedy Memory Eater" and Error 303 (From: Andreas Grosam <email@hidden>)
 >Re: NSURLConnection: "Greedy Memory Eater" and Error 303 (From: David Duncan <email@hidden>)

  • Prev by Date: Re: Lion breaks the ability to "click-through" transparent window areas when the window is resizable.
  • Next by Date: Re: NSURLConnection: "Greedy Memory Eater" and Error 303
  • Previous by thread: Re: NSURLConnection: "Greedy Memory Eater" and Error 303
  • Next by thread: Re: NSURLConnection: "Greedy Memory Eater" and Error 303
  • Index(es):
    • Date
    • Thread