7

I've recently noticed that when I load a webview based off code from a file (using assets or a local directory), the WebView will leak the memory once the destroy() method is called. I've narrowed it down to a referencing issue. The program/webview makes copies of the original view and loses the references in the JNI table - this eventually causes the program to crash after 512 entries.

I have seen this article, but the non-leaking webview fix does not seem to work with HTML in the assets or external folders.

Memory leak in WebView

The issue does not exist when the application is entirely server based; but, I need the application to be able to "sync" data and update the offline repo with these views.

Further info: I have taken the webviews and put them in a ViewPager to allow for scrolling. This issue did not exist in 3.2.4/1 but has appeared in 4.0.3. I get a lot of JNI Warnings, (failed to find entry) and they still exist after the views are destroyed. I've looked at it through the hprof, and I have noticed that the HTML is staying residual in lost variables.

Any light on how to correct this behavior would be appreciated.

Edit:

Specifics on the crash

Failed adding to JNI local ref table (has 512 entries)
"Thread-375" prio=5 tid=15 RUNNABLE
| group="main" sCount=0 dsCount=0 obj=0x41504a90 self=0x1a9cf80
| sysTid=10314 nice=0 sched=0/0 cgrp=default handle=27159240
| schedstat=( 455083000 66745000 774 ) utm=30 stm=15 core=3

at android.content.res.AssetManager.readAsset(Native Method)
at android.content.res.AssetManager.access$700(AssetManager.java:35)
at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:573)
at dalvik.system.NativeStart.run(Native Method)

UPDATE:

To fix this issue, you have to load from the SD Card, or some other storage mechanism. The bug is permanent when a Javascript file is loaded, I don't know if it's fixed in Chrome, but it does not seem to be fixed in Browser in the newest OS.

Community
  • 1
  • 1
Alex Kelly
  • 1,593
  • 3
  • 14
  • 19
  • 1
    try to load files from SD card code: webtemp.loadUrl("file://"+Environment.getExternalStorageDirectory()+"/assetssd/example.html); – LOG_TAG Jun 12 '12 at 05:57
  • 2
    Are you serious...? I was the person who emailed this answer >.> – Alex Kelly Jun 14 '12 at 19:35
  • 1
    Joke of the day!! thanks for I identifying!! :) !My friend Yes you are Right!:) sorry for that!I doesn't seen the asked name while commenting!! finally the ans is out!! but the above "local ref table" error solved but "E/dalvikvm-heap(16169): Out of memory on a 2310160-byte allocation." error comes!!! – LOG_TAG Jun 16 '12 at 05:47
  • Lol! It's okay :P I should have posted this on many other forums and bug reports. oh well. – Alex Kelly Jul 05 '12 at 14:35

1 Answers1

2

.destroy() --> Destroys the internal state of this WebView. This method should be called after this WebView has been removed from the view system.

nurisezgin
  • 1,530
  • 12
  • 19