UIWebView leaks, JS Garbage Collector & WebCore VMs
Asked Answered
K

1

21

I've been building a browser feature for an app which obviously works with UIWebView. I've been seeing memory jump up when the browser opens which makes sense, however i'm seeing some troubling results during a leaks profile:

Leaks profiling

The VM: JS garbage collector and VM: WebCore purgeable data just keep climbing the more I browse. Whats even worse is that when the browser is deallocated and it's web view released, these objects are still there, taking up upwards of 6 MB of memory.

I'm not sure what if i'm not handling UIWebView correctly but there seems to be an issue with this memory being held on to after the UIWebView is deallocated.

I perform some cleanup prior to the browser being deallocated as detalled in this post http://www.codercowboy.com/code-uiwebview-memory-leak-prevention/ but this doesnt seem to be making any difference.

Has anyone had this issue? Any insight would be awesome. I've seen a few questions already related to UIWebView memory issues however they don't specifically detail the results of a profile.

Kirksey answered 27/11, 2013 at 5:16 Comment(1)
I'm seeing the same problem, iOS 7.1 too. I have a very simple example project here:bitbucket.org/tassinari/mtwebviewtest I've also filed a bug openradar.me/radar?id=5869182600085504Taster
A
1

I'm unsure if I would immediately consider this a problem. Those VMs only start when you add a web view to your view hierarchy and load a request with it.

It may just be the OS that keeps those resources alive in case they will be used again.

I tried to replicate your code that cleans up the data and had drops of 50%.

The JS Garbage collector was always at around 3MB minimum, but had maximums of 8MB The WebCore purgeable data was always at around 700KB

You may also consider that this may be related to bad JavaScript that continues to live because of leaks in the JavaScript code.

Abatis answered 15/12, 2013 at 12:36 Comment(2)
Any scenario where memory usage climbs as the user continues to interact, without a way to stop it, I would consider quite a serious issue. 3 MB is a lot of memory in the mobile world, especially when it's effectively doing nothing. if theres a way to dispose of it, I'd like to do it.Kirksey
I tried something else in the simulator, sending a memory warning after deallocing the web view. It cut down the total memory to 2.1MB in both VMs you mentioned. Since we are talking about web resources, I'm unsure there is a way to cut down memory usage if it starts to eat up too much memory. We just don't have the kind of memory management options we have with native resources.Abatis

© 2022 - 2024 — McMap. All rights reserved.