1

I have Samsung Galaxy S4 (Android 5.0.1). I tested 2 applications with a WebView.

1) In one of them a geographical map is used with marks and lines (paths). After 10-20 shifts and zooms it crushed with OutOfMemory.

2) In the second a site of a company is used integrated in Cordova. After 20-60 page loadings it also crushes with OutOfMemory. When I see a memory allocation, it acts like a saw: after an increase up to some limit it frees, then again increases. After 2-4 peaks it crushes.

On some other devices these crushes are not reproduced. The same is in replies at PlayMarket.

I read many articles including http://www.dwmkerr.com/fixing-memory-leaks-in-angularjs-applications/. An application uses Angular JS. When I tested it in Chrome and Firefox developer's console I saw that after peaks up to 12 Mb a garbage collector in a browser started.

I have these questions.

1) Does a WebView have it's own garbage collector (I think, Javascript GC)?

2) If a WebView is just a View, why it is not destoroyed, but a whole application crushes?

3) How Android GC can affect WebView (maybe Chromium GC) and how WebView can tell Android GC to free a memory?

CoolMind
  • 26,736
  • 15
  • 188
  • 224
  • 1
    See http://stackoverflow.com/a/16530168 for an answer on GC. You may want to use CrossWalk in your Android apps so that on all Android devices you'll be using the same webview (note that depending on the CrossWalk version, some Android versions are not compatible). – user276648 Sep 14 '16 at 00:42
  • @user276648, thanks, I also saw it, then tried to setup a CrossWalk (but couldnot, and it adds some weight to apk). Probably this article (https://auth0.com/blog/four-types-of-leaks-in-your-javascript-code-and-how-to-get-rid-of-them/) can be interesting, I also made some researches in that way. – CoolMind Sep 14 '16 at 07:26
  • As I understood, a problem has been solved. Developers upgraded an old version of Cordova. – CoolMind Jun 19 '17 at 09:39

1 Answers1

0

As nobody answered, I reply.

I connected devices to Chrome, entered "chrome://inspect" and watched a spreading of memory (including JS Heap) on time. On Samsung devices a memory constantly increased after events in WebView. On HTC (Android 2.3.3) it increased, then again cleaned by GC (every second). On Samsung Galaxy S4 it raised from 20 Mb up to 30 and then crushed. On Galaxy Tab A it started from 7 Mb and so didn't crush.

A Chrome developer console also showed a work of GC in WebView. Sometimes it launched Major GC, sometimes Minor GC. I think, that was a Javascript GC inside WebView, as it had not led to cleaning memory in Java.

1) Every implementation of a browser on every platform has it's own GC (including Javascript GC).

2) WebView is a very complex View, so it may easily crush an application.

3) I think, Android may ask WebView to free some memory, it launches it's GC. But depending on the platform it can decrease a used memory by WebView (on HTC 2.3.3) or leave it intact. So even if a GC was run in WebView, it often won't free memory in the application.

CoolMind
  • 26,736
  • 15
  • 188
  • 224