Android WebView leak when using assets

I recently noticed that when I load code based on code from a file (using assets or a local directory), WebView will leak memory after calling destroy (). I narrowed it down to the link. The program / webview makes copies of the original view and loses references in the JNI table - this ultimately leads to the program crashing after 512 entries.

I saw this article, but the webview non-leak fix doesn't seem to work with HTML in assets or external folders.

Memory leak in WebView

The problem does not exist when the application is completely server-based; but I need the application to be able to "synchronize" the data and update the offline repo with these views.

Additional info: I browsed the web pages and placed them in the ViewPager to allow scrolling. This question did not exist in 3.2.4 / 1, but appeared in 4.0.3. I get a lot of JNI warnings, (could not find the record), and they still exist after destroying the views. I looked through it through hprof and I noticed that the HTML remains residual in the lost variables.

Any light on how to fix this behavior will be appreciated.

Edit:

Accident features

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 problem, you need to download from an SD card or other storage engine. The error loads when the Javascript file loads, I don’t know if this is fixed in Chrome, but it doesn’t look like a fix in the browser on the latest OS.

+6
source share
1 answer

.destroy () β†’ Destroys the internal state of this WebView. This method should be called after this WebView has been removed from the viewer.

+1
source

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


All Articles