我現在正在開發一個Iphone應用程序,它需要用戶登錄Facebook並將其數據傳遞到webService並登錄到我的遊戲。基本上我的遊戲是由HTML運行的,並且會在我的應用程序中通過UIWebView顯示。運行時收到內存警告UIWebView
這裏是我的代碼加載web視圖:
-(void)callWebView {
self.webView.delegate = self;
NSURL *url = [NSURL URLWithString:@"http://www.my_game_url"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestURL];
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
if ([ urlString isEqualToString: @"http://my_game_logout_url" ]) {
[myWebView stopLoading];
[self.webView removeFromSuperview];
MyAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.session closeAndClearTokenInformation];
[FBSession.activeSession close];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];
return NO;
}
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[self.webView stopLoading];
MyAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.session closeAndClearTokenInformation];
[FBSession.activeSession close];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
webView.delegate = nil;
[webView stopLoading];
}
- (void)dealloc {
[webView setDelegate:nil];
}
這是罰款,我運行遊戲的UIWebView。問題是我會後來收到內存警告,我的應用程序將崩潰。我必須啓用自動引用計數(ARC)才能自動釋放一些不需要的源,但我仍會在我的應用程序中收到內存警告。有什麼我實施錯誤? 謝謝。
在樂器+ heapshots中使用分配=> http://useyourloaf.com/blog/2011/03/08/using-heapshots-to-find-abandoned-memory.html – Peres 2013-04-11 09:01:56