问题
I'm struggling with memory management in iOS while downloading relatively large files from the web (such as videos with 350MB size). The goal here is to download these kind of files and store it on CoreData on a Binary Data field.
At the moment I'm using NSURLSession
.dataTaskWithUrl
and NSURLSession
.dataTaskWithRequest
methods to retrieve these files, but it looks like these methods don't treat problems such as memory usage, they just keep on filling the memory until it reaches its maximum usage, leaving me with a memory warning when I reach 380MB~.
Initial Memory Usage
Memory Warning
What's the best strategy to perform this kind of large data retrieval from the web without reaching a memory warning? Does AlamoFire and other libs can deal with this problem?
回答1:
It is better to use download task.
And save the video as a file to Document or Library directory.
Then save the relative path to CoreData
If you use download task
- You can resume if last download fail
- Need less memory
回答2:
You can try AFNetworking to download large files.
来源:https://stackoverflow.com/questions/34089651/ios-strategies-for-downloading-very-large-data-from-web