5
你好,我有一个UIWebView泄漏内存的问题基本上我有我的WebView显示页面的链接是从另一个控制器的UITableView.I推动与导航器的WebView的控制器,并通过与链接保留财产。IOS的UIWebView泄漏
我已经试过各种方法在互联网上,如:
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
//Clear cache of UIWebView
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
sharedCache = nil;
[[NSURLCache sharedURLCache] removeAllCachedResponses];
这是我的代码:
-(void) viewWillAppear:(BOOL) animated
{
NSMutableURLRequest *_req=[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:120];
[_req setHTTPShouldHandleCookies:NO];
[self setMyRequest:_req];
[req release];
}
[webView loadRequest:myRequest];
-(void) viewWillDisappear:(BOOL) Animated
{
[webView stopLoading];
[webView loadHTMLString:@"<html></html>" baseURL:nil];
}
- (void)dealloc {
[myRequest release];
[webView stopLoading];
[webView release];
[link release];
[super dealloc];
}
现在我只在模拟器4.2和4.3上测试过,我使用xcode 4,当我点击导航器上的后退按钮时,我得到了这个漏洞。
这里是从我的tableview控制器
- (void)viewDidLoad {
webViewController=[[ItemDetail alloc] initWithNibName:@"ItemDetail" bundle:[NSBundle mainBundle] ];
[super viewDidLoad];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
webViewController.link=http://www.myLink.com;
[self.navigationController pushViewController:webViewController animated:YES];
}
-(void) dealloc
{
[webViewController release];
...
...
[super dealloc];
}
这里的代码到屏幕的链接:http://postimage.org/image/368r0g0xw/
任何帮助,将不胜感激, 感谢
你的一行代码出现在任何方法之外,你可以发布你的实际代码吗?这不会编译。 “myRequest”在哪里被分配/分配?关于'link'呢?你有没有为UIWebView设置一个委托? – Jim 2011-06-10 16:05:40
对不起,我现在会发布代码 – 2011-06-29 08:43:54