Search code examples
ioscore-datarestkitios9sdwebimage

App freezes if a lot of images are loading in iOS 9


My App freezes since iOS 9 if I load a lot of images. Our web server sometimes has problems to deliver all images (gateway timeout), so the app freezes until timeout. There is no error and the app is just fine after that. I'm using SDWebImage and RestKit. I can reproduce the freeze in the simulator. I didn't have this problem with iOS 8. Before I send a request to our server, I remove all cached responses: [[NSURLCache sharedURLCache] removeAllCachedResponses];

The app freezes in semaphore_wait_trap.

The last line of RestKit thread is self.cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:requestOperation.request];.

The last line of SDWebImages thread is if (![[NSURLCache sharedURLCache] cachedResponseForRequest:_request]).

If I pause the debugging during the freeze, I get this output in the debug navigator window (The YPIclasses are my own): debug navigator window

Thanks a lot for your help.


Solution

  • Found the reason: [[NSURLCache sharedURLCache] removeAllCachedResponses]; before sending the requests caused the UI hang. After removing these lines and disabling NSURLCache for the whole app, the problem disappeared:

    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];