使用Assets时Android WebView内存泄漏 [英] Android WebView Memory Leak when using Assets

查看:18
本文介绍了使用Assets时Android WebView内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近注意到,当我从文件(使用资产或本地目录)加载基于代码的 webview 时,一旦调用 destroy() 方法,webview 就会泄漏内存.我已将其缩小为参考问题.程序/webview 复制原始视图并丢失 JNI 表中的引用 - 这最终导致程序在 512 个条目后崩溃.

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 修复似乎不适用于资产或外部文件夹中的 HTML.

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 内存泄漏

当应用程序完全基于服务器时,该问题不存在;但是,我需要应用程序能够同步"数据并使用这些视图更新离线存储库.

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.

更多信息:我已经获取了 webviews 并将它们放在 ViewPager 中以允许滚动.此问题在 3.2.4/1 中不存在,但在 4.0.3 中出现.我收到了很多 JNI 警告,(无法找到条目)并且在视图被销毁后它们仍然存在.我通过 hprof 查看过它,我注意到 HTML 在丢失的变量中保持残留.

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.

崩溃的细节

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)

更新:

要解决此问题,您必须从 SD 卡或其他一些存储机制加载.加载 Javascript 文件时该错误是永久性的,我不知道它是否在 Chrome 中修复,但它似乎没有在最新操作系统的浏览器中修复.

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.

推荐答案

.destroy() --> 销毁此 WebView 的内部状态.此方法应在此 WebView 从视图系统中删除后调用.

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

这篇关于使用Assets时Android WebView内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆