Hello i am having problems with an UIWebView leaking memory basicaly i have my WebView display pages with the links being in an UITableView from another controller.I push the controller with the WebView with an navigator and pass the link with a retain property to it.
I have tried everything on the internet like:
[[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];
this is my code:
-(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];
}
Now I only tested in on simulator 4.2 and 4.3, i use xcode 4, i get this leaks when i hit the back button on the navigator.
And here is the code from my tableview Controller
- (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];
}
Here is a link to a screen: http://postimage.org/image/368r0g0xw/
Any help would be appreciated, Thanks
-(void) viewWillAppear:(BOOL) Animated
{
//CONNECTION INIT
[web setDelegate:self];
NSURL *url=[[NSURL alloc] initWithString:link];
NSURLRequest *_req=[[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:120];
[self setReq:_req];
[_req release];
[url release];
[web loadRequest:req];
}
-(void) viewWillDisappear:(BOOL) Animated
{
[self setReq:nil];
if ([web isLoading])
[web stopLoading];
[web setDelegate:nil];
}
- (void)dealloc {
[req release];
[map release];
[web setDelegate:nil];
[web release];
[link release];
[super dealloc];
}
Now i release it after i go back to the table view, it still leaves about 3 mb after i release it, but now when i create the view again and release it again those 3mb are unchanged. Weird...
Item Detail *webViewController=[[ItemDetail alloc] initWithNibName:@"ItemDetail" bundle:[NSBundle mainBundle] ];
[self.navigationController pushViewController:webViewController animated:YES];
[webViewController release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With