Re: NSURLConnection: "Greedy Memory Eater" and Error 303
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:26:05 +0200
On Sep 9, 2011, at 4:15 PM, glenn andreas wrote:
>
> On Sep 9, 2011, at 6:06 AM, Andreas Grosam wrote:
>
>> Dir Members,
>>
>> I'm trying to use a NSURLConnection to download a large data file (>10 MB) from a web service to the iPhone. Currently, testing on iOS 4.2.1, on a device. The connection is established over WIFI.
>>
>> 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.
>
>
> For another datapoint, I've got an app that can (optionally) download a 12.9MB data file which uses NSURLConnection, and it works fine - no threading, just the standard asynch delegate callbacks. I need to make sure that I'm accumulating the data in a file instead of in memory (in connection:didReceiveData:), but there's no problem with crashing or other weird errors.
>
>
>
> Glenn Andreas email@hidden
> The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL
>
This kind of use case seems to work. Writing to a file seems fast enough (relative to reading from a WIFI network), and it seems not to use much additional memory.
The faster the data buffers are processed (relative to producing it) the smaller the buffers get. The smaller the buffers, the less memory will be used by the connection.
I would rather process the data as they come in. Well, in theory I could process about 0.5..1.0 Mbyte per second on a slow old iPhone - if I had the CPU exclusively, and some RAM ;)
If I can't find a solution, I have to resort to write to a temporary file. It seems strange however, that the internal buffers of NSURLConnection can grow that large and why these large buffers might be beneficial when streaming in from a network._______________________________________________
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