My iOS app is downloading a very large zip file (of 3.79GB) using AFNetworking. My app also used Flipboard's FLEX library 2.2 to monitor the network traffic. A user reported that once the app trigger the download request, the app crashes with the following stacktrace:
Crashed Thread
0 CoreFoundation 0x22c6010b __exceptionPreprocess + 124
1 libobjc.A.dylib 0x22406e17 objc_exception_throw + 36
2 CoreFoundation 0x22c60051 +[NSException raise:format:] + 110
3 Foundation 0x233bed7d -[NSConcreteMutableData initWithCapacity:] + 106
4 previewer 0x001e9c3d __86-[FLEXNetworkObserver(NSURLConnectionHelpers) connection:didReceiveResponse:delegate:]_block_invoke (FLEXNetworkObserver.m:946)
5 libdispatch.dylib 0x227d9b5b _dispatch_call_block_and_release + 8
6 libdispatch.dylib 0x227e675b _dispatch_queue_drain$VARIANT$mp + 1756
7 libdispatch.dylib 0x227e5d99 _dispatch_queue_invoke$VARIANT$mp + 282
8 libdispatch.dylib 0x227e8495 _dispatch_root_queue_drain + 394
9 libdispatch.dylib 0x227e8305 _dispatch_worker_thread3 + 94
10 libsystem_pthread.dylib 0x22997b29 _pthread_wqthread + 1022
11 libsystem_pthread.dylib 0x22997718 start_wqthread + 6
The crash reason:
NSInvalidArgumentException: *** -[NSConcreteMutableData initWithCapacity:]: absurd capacity: 3794795864, maximum size: 2147483648 bytes
and it occurs at the following lines at FLEXNetworkObserver
:
if (response.expectedContentLength < 0) {
dataAccumulator = [[NSMutableData alloc] init];
} else {
dataAccumulator = [[NSMutableData alloc] initWithCapacity:(NSUInteger)response.expectedContentLength];
}
He was using iPad 3 and he said he cannot reproduce the problem using his newer iPad mini 3. May I know if that is caused by the 32-bit limitation of older iPad model (in this case iPad 3)? What is the reason causing the crash?
I will disable FLEX network debugging as a workaround to this problem.
Update
I can successfully download the file after disabling FLEX by [[FLEXManager sharedManager] setNetworkDebuggingEnabled:NO];
, so that's not related to AFNetworking at all.
My iOS app is downloading a very large zip file
The fact that an NSMutableData is being set aside to hold it suggests that the plan here is not to download the file but to treat it as data to be held the whole time in memory. That is very wrong, esp. since your app could well crash if it tried to hold such a large object in memory. A true download would download to disk and virtually no memory would have to be set aside.