Oscar
Oscar

Reputation: 1929

Memory issue downloding a large file

I have a big issue that I can't solve. I'm making an iPad app & downloading a zip file in it (large one, like 80Mb) & at some point, like 75%, the app is crashing... I executed profile & i can see how the memory is growing with the downloading, so, it is clearly a memory issue. My question is , how can I solve this properly? can I release some of this memory in some way. Tell me if I need to put some source code here & thank u in advance! Regards!

Upvotes: 0

Views: 546

Answers (2)

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

you need to use NSOutputStream and write it to the disk directly instead of keeping it in the memory till complete download. This approach will reduce the usage of runtime memory and will resolve your crashing issue.

look at this method in the API reference

+ (id)outputStreamToFileAtPath:(NSString *)path append:(BOOL)shouldAppend

Here is some reference on Streams: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSOutputStream_Class/Reference/Reference.html

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSInputStream_Class/Reference/Reference.html

Upvotes: 3

Jake
Jake

Reputation: 3973

Don't keep the downloaded bytes in memory but write them to disk in the order that you receive them in. If you don't know how, ASIHTTPRequest can help you.

Upvotes: 3

Related Questions