一旦closures,从UIWebView释放内存/ cookie /caching

我有一个UIViewController ,其中包含一个UIWebView

我使用UIViewController中的UIWebviewlogin到Facebook的网站,然后我点击完成,这将closures视图控制器,我想这将释放视图控制器。 但是当我再次打开UIWebview(没有退出应用程序,甚至在终止应用程序之后),网页视图加载后仍然login到Facebook。 我应该如何发布Web视图,以便每次点击完成并返回到Web视图时,Web视图将始终像“全新”一样,而不是login到之前login过的任何网站。

 - (void)viewDidLoad{ NSLog(@"webView viewDidLoad called"); appDelegate = (LoginDBAppDelegate *)[[UIApplication sharedApplication] delegate]; loginObj = [appDelegate.loginArray objectAtIndex:currentSelectedRow]; myWebView.delegate = self; [super viewDidLoad]; [self showWebView]; } -(void)showWebView{ NSLog(@"webView showWebView called"); NSURL *url = [NSURL URLWithString:loginObj.loginURL]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [myWebView loadRequest:request]; } -(IBAction)done_Clicked:(id)sender{ NSLog(@"webView Done_Clicked"); //dismiss the controller [self.navigationController dismissModalViewControllerAnimated:YES]; } -(void)dealloc{ [myWebView release]; myWebView.delegate = nil; [activity release]; [urlTextField release]; [super dealloc]; } 

我已经尝试过,但没有奏效:

 -(IBAction)done_Clicked:(id)sender{ NSLog(@"webView Done_Clicked"); [[NSURLCache sharedURLCache] removeAllCachedResponses]; [myWebView stringByEvaluatingJavaScriptFromString:@"var body=document.getElementsByTagName('body')[0];body.style.backgroundColor=(body.style.backgroundColor=='')?'white':'';"]; [myWebView stringByEvaluatingJavaScriptFromString:@"document.open();document.close()"]; //dismiss the controller [self.navigationController dismissModalViewControllerAnimated:YES]; } 

我也试过这个没有成功:

 - (void) viewDidDisappear:(BOOL)animated { NSLog(@"webView viewDidDisappear called"); [super viewDidDisappear:animated]; [self.myWebView removeFromSuperview]; self.myWebView.delegate = nil; self.myWebView = nil; [myWebView release]; } 

得到了论坛上的人的答案,所以信用他…

将此代码放在viewDidLoad中

 //Set Cache NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; //Clear All Cookies for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { //if([[cookie domain] isEqualToString:someNSStringUrlDomain]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; }