Afnetworking: download large file crash

Created on 22 Dec 2017  ·  5Comments  ·  Source: AFNetworking/AFNetworking

[manager setDataTaskDidReceiveDataBlock:^(NSURLSession * _Nonnull session, NSURLSessionDataTask * _Nonnull dataTask, NSData * _Nonnull data) {
....
}

[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
...
}

when download large file(more than 1G),
this code :
[self.mutableData appendData:data];
in AFURLSessionManager.m will cause memery growup

“self.mutableData” this object will become biger and biger. it will not release until download finish. And app will crash.

Most helpful comment

Why on earth would you try to download into memory a 1GB sized file?

Thats a clean download to disc use case, if you change the download into a download task it should work correctly

All 5 comments

Why on earth would you try to download into memory a 1GB sized file?

Thats a clean download to disc use case, if you change the download into a download task it should work correctly

@ArkadiYoskovitz "change the download into a download task", can this way set the start offset? i need to resume from the break point.

Are you trying to resume a failed download? -[AFURLSessionManager downloadTaskWithResumeData:progress:destination:completionHandler:] should be able to handle that for you.

@SlaunchaMan -[AFURLSessionManager downloadTaskWithResumeData:progress:destination:completionHandler:]this has another problem. I can't get the resumeData that if i kill the app. Is there any suggestion?

@shantj Why not trying this?

[AFURLSessionManager downloadTaskWithRequest:progress:destination:completionHandler:]
Was this page helpful?
0 / 5 - 0 ratings