views:

415

answers:

2

Hello, I have a problem with memory management.

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.

Am I missing something? Anyone know what could be happening?

Thank you!

A: 

You'll need to show the relevant code. While UIWebView can leak memory, you're leaking such huge amounts that it's likely you're responsible for the leak(s) somewhere.

Shaggy Frog
A: 

Hi.

If you add multiple subviews within the same instance of a viewcontroller, you must remove the old subview from the superview before you add a new subview.

Add a tag to the UIWebView before you add it as a subview:

webView.tag  = 10;
[self.view addSubview:webView];

webView = nil;

Before you add the new webview(this will clear the old view), remove the subview from the superview:

UIWebView * oldWebView = (UIWebView *)[self.view viewWithTag:10];
[oldWebView removeFromSuperview];

If you don´t remove the old webviews from the superview, they will build up in memory until you release the viewcontroller.

Elias