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.
我最近注意到,当我从文件(使用资源或本地目录)加载基于代码的webview时,一旦调用destroy()方法,WebView将泄漏内存。我把它缩小到一个引用问题。程序/ webview制作原始视图的副本并丢失JNI表中的引用 - 这最终导致程序在512个条目之后崩溃。
I have seen this article, but the non-leaking webview fix does not seem to work with HTML in the assets or external folders.
我已经看过这篇文章了,但是非泄漏的webview修复似乎不适用于资产或外部文件夹中的HTML。
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.
进一步的信息:我已经采取了网络视图并将它们放在ViewPager中以允许滚动。这个问题在3.2.4 / 1中不存在,但已出现在4.0.3中。我得到了很多JNI警告,(找不到条目)并且在视图被销毁后它们仍然存在。我已经通过hprof查看了它,我注意到HTML在丢失的变量中保留了残差。
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.
要解决此问题,您必须从SD卡或其他存储机制加载。当加载Javascript文件时,该错误是永久性的,我不知道它是否已在Chrome中修复,但在最新的操作系统中似乎没有在浏览器中修复。
1 个解决方案
#1
1
.destroy() --> Destroys the internal state of this WebView. This method should be called after this WebView has been removed from the view system.
.destroy() - >破坏此WebView的内部状态。在从视图系统中删除此WebView之后,应调用此方法。
#1
1
.destroy() --> Destroys the internal state of this WebView. This method should be called after this WebView has been removed from the view system.
.destroy() - >破坏此WebView的内部状态。在从视图系统中删除此WebView之后,应调用此方法。