views:

166

answers:

3

Hi guys, I have a problem using UIWebViews, I've seen the same question here but there wasn't helpful answer. the question is here: http://stackoverflow.com/questions/2950907/uiwebview-memory-management . I will quote it:

I am developing an application that makes heavy use of UIWebView. This app generates dynamically lots of UIWebViews while loading content from my server. Some of these UIWebViews are quite large and have a lot of pictures.

If I use instruments to detect leaks, I do not detect any. However, lots of objects are allocated and I suspect that has to do with the UIWebViews.

When the webviews release because no longer needed, it appears that not all memory is released. I mean, after a request to my server the app creates an UITableView and many webviews (instruments say about 8Mb). When user tap back, all of them are released but memory usage only decrements about 2-3 Mb, and after 5-10 minutes using the app it crashes.

I have created simple test app and have the same results.

It's a tableView, I'm creating DetailsView like this:

DetailsVC *detailViewController = [[DetailsVC alloc] initWithNibName:@"DetailsVC" bundle:nil];
detailViewController.n = indexPath.row;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

in DetailsVC I have a webView created in IB. I load html like this:

    NSString *urlAddress;
if (self.n == 0)
{
    urlAddress = @"http://www.google.com";
}
else 
{
    urlAddress = @"http://www.yahoo.com";
}

NSURL *url = [NSURL URLWithString:urlAddress];

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[self.webView loadRequest:requestObj];

I also do:

- (void)viewDidUnload {
self.webView = nil;
}

That's it, every time I choose any webView in RootViewController I'm loosing 2-3 Mb of memory, Is there a solution to this problem?

Thanks.

A: 

I guess that since you set webview=nil, you loose any chance to release it

VdesmedT
I tried with it and without it, it actually doesn't matter, it's being released, but but not only part of memory is freed
Burjua
A: 

Just check the following 1. Is u make the webview as property remove it 2. And put the following code in "didFinishLaunchingWithOptions" in Appdelegate

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release];

I think then ur problem is solved

NaveenShan
Ok, thanks, I will try it
Burjua
No, unfortunately this doesn't help :((
Burjua
A: 

Hi Burjua,

have you ever been able to resolve this problem?

I seem to run into the same problem and the suggestions above have not solved this issue for me either.

My WebView is created via NIB, wired up and whenever there is a memory warning and the view that contains the webView is no longer needed I try to free up memory in viewDidUnload:

- (void)viewDidUnload { 
[super viewDidUnload];
[browserWebView stopLoading];
browserWebView.delegate = nil;
[browserWebView removeFromSuperview];
[browserWebView release];
// retain count is 1
browserWebView = nil;             }

Thank you, Ralph

Ralph
I decided to open my own quesion so that I can provide much more details. See: http://stackoverflow.com/questions/3982955/uiwebview-when-or-how-does-cfdata-get-released
Ralph
It looks like everyone has the same problem, but there is no solution to it(((
Burjua