我现在正在开发一个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