UIWebView memory leak

I have an iPad application (iOS 4.3 and 5.0) that creates a UIView with at least two subqueries each time a user's pages go forward or backward. The 2 subclauses are UIWebView objects.

With each appropriate scroll, the old UIWebViews are removed and freed up properly (removeFromSuperview, then stopLoading and set the delegate to nil), and the parent UIView is freed. I can confirm that both parent UIView and 2 child UIWebViews have completely disappeared.

I see a save counter on webviews as they are deleted, and I am sure that they really are deleted every time. However, the memory distribution continues to increase with each scroll ~ 200-350 thousand. There are no leaks in the tool, but I see that the memory usage is slowly growing. On iPad 1, the application eventually (within 6-10 minutes of moderate use) receives several memory warnings and stops. A LowMemory alarm log is created ... etc.

We use stringByEvaluatingJavaScriptFromString and loadRequest to populate Webviews. Memory usage increases even when nothing is entered or loaded into webViews.

Does anyone experience this behavior with UIWebViews? Has anyone dealt with this successfully?

I would like comments and answers to be appreciated.

+4
source share
3 answers

Try using the Tools, but with the "Highlights" template and look at the "# Living" columns for UIWebView. I usually use it as follows:

  • Profile application with Highlight template
  • "Make a joke" application by going through all the tabs, scrolling, etc.
  • Click "Mark Heap", this will create a "Source" heap.
  • Do what you think makes objects stay away.
  • Click "Mark Heap" again, this will create a "Heapshop #" heapshot
  • Inspect the objects in "Heapshop #", which will show the size and number of objects created and live since the last heap.
  • Goto 4
+1
source

No leak is known, but if you destroy and recreate the same hierarchy of views each time, why not save the views and reuse them instead?

Regardless of whether they are leaking, webviews are computationally expensive to set up, so reusing them and just reloading the content should give you better performance and may also fix your leak.

0
source

Do you still see this problem? I traced something that looks like unlimited memory usage (not necessarily a leak, but I get low memory warnings and a possible process termination), again calling stringByEvaluatingJavaScriptFromString:

[webview stringByEvaluatingJavaScriptFromString:@"something()"]; 

Something seems to be wrong there.

0
source

Source: https://habr.com/ru/post/1392114/


All Articles