Reputation: 9481
So I have an app that is going to download lots of files, ranging from pngs to pdfs.
The problem it seems if there is too much data, it will crash. In Xcode, it gives a Memory error. If I run it in simulator it will work fine, but on the iPhone it will crash.
We're talking about 40 MB of data, but when I look at the memory monitor it seems to be skyrocketing like around 300-500 MB of memory used. I believe when it crashes when its in the process of downloading the 35 MB PDF. I am using AFNetworking to download the data. Any help would be greatly appreciated.
I don't really have any code to show because it's basically crashing when it's doing the asynchronous download that AFNetworking does.
Upvotes: 1
Views: 837
Reputation: 3564
I know the question is relatively old, but I have the same problems with memory and downloading many big files through AFNetworking.
AFNetworking seems to cache dependent on the Cache-Policy of your NSURLRequest.
I worked first with:
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString]];
and had every time if I starts downloading many files memory problems.
Now I set the Cache-Policy on the NSURLRequest explicitly and I have no memory problems anymore :)
New Call:
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30];
This points me in the right direction: https://github.com/AFNetworking/AFNetworking/issues/109
Maybe this helps you with your problem?
Upvotes: 0
Reputation: 5290
I've never understood AFNetworking's popularity. It facilitates doing downloads incorrectly, causing exactly this problem. You would do better to simply use NSURLConnection sendAsynchronousRequest:queue:completionHandler:.
Upvotes: 1