From 8b74eaff1f16b230665b91ba7b34b3c90ede5f8c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 21 Mar 2011 04:27:21 -0700 Subject: Don't lose track of network activity during memory warnings. --- CyteKit/WebViewController.mm | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm index 2298d75..a38a8d0 100644 --- a/CyteKit/WebViewController.mm +++ b/CyteKit/WebViewController.mm @@ -148,14 +148,21 @@ float CYScrollViewDecelerationRateNormal; return true; } +- (void) releaseNetworkActivityIndicator { + if ([loading_ count] != 0) { + [loading_ removeAllObjects]; + + if ([self retainsNetworkActivityIndicator]) + [delegate_ releaseNetworkActivityIndicator]; + } +} + - (void) dealloc { #if LogBrowser NSLog(@"[CyteWebViewController dealloc]"); #endif - if ([loading_ count] != 0) - if ([self retainsNetworkActivityIndicator]) - [delegate_ releaseNetworkActivityIndicator]; + [self releaseNetworkActivityIndicator]; [super dealloc]; } @@ -352,7 +359,11 @@ float CYScrollViewDecelerationRateNormal; } - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame { - [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]]; + NSValue *object([NSValue valueWithNonretainedObject:frame]); + if (![loading_ containsObject:object]) + return; + [loading_ removeObject:object]; + [self _didFinishLoading]; if ([[error domain] isEqualToString:NSURLErrorDomain] && [error code] == NSURLErrorCancelled) @@ -500,7 +511,10 @@ float CYScrollViewDecelerationRateNormal; } - (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame { - [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]]; + NSValue *object([NSValue valueWithNonretainedObject:frame]); + if (![loading_ containsObject:object]) + return; + [loading_ removeObject:object]; if ([frame parentFrame] == nil) { if (DOMDocument *document = [frame DOMDocument]) @@ -906,6 +920,8 @@ float CYScrollViewDecelerationRateNormal; webview_ = nil; scroller_ = nil; + [self releaseNetworkActivityIndicator]; + [super releaseSubviews]; } -- cgit v1.2.3