的WebView内存泄漏 [英] WebView memory leak

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

问题描述

抱歉,如果这是某种形式的重复问题。我GOOGLE了大约一个小时,但仍然有web视图组件的内存使用的问题。

Sorry if this is some kind of duplicate question. I googled for about an hour but still have problems with the memory usage of the WebView component.

我开始从ListActivity的活动(阅读新闻),以显示特定的新闻文章。文章的HTML的code加入到包括在活动布局的WebView。 (它也可以通过加载1或2图像的 newsDetail.loadDataWithBaseURL()的)

I'm starting an Activity (NewsDetail) from a ListActivity to display a specific news article. The HTML-Code of the article is added into the WebView which is included in the Activity layout. (it also loads 1 or 2 images via newsDetail.loadDataWithBaseURL())

我开始通过文章活动:

Intent i = new Intent(getApplicationContext(), NewsDetail.class);  
i.putExtra("position", position);
startActivity(i);

问题后,我改变了我的布局,使我编程方式添加的WebView:

After reading this question, I changed my Layout so that I add the WebView programmatically:

newsDetail = new WebView(getApplicationContext());

在我的onDestroy方法设置:

In my onDestroy method is set:

public void onDestroy(){
    super.onDestroy();
    newsDetail.destroy();
    newsDetail = null;
    finish();
    System.gc();
}

一段时间后,垃圾收集减少内存大约4 MB的金额为2 MB。如果我打开/关闭一些新闻文章它上升到一个临界堆大小。 :/

After a while, the Garbage Collector reduce the amount of memory from about 4 MB to 2 MB. If I open/close several news articles it rises to a critical heap size. :/

如前所述,破坏活动后,还有的留下来的活动(如果我完全从code取出的WebView不存在)2 MB休息。因此,似乎有某事做web视图本身。
同样的问题在这里提到的。

As mentioned, after destroying the activity, there's a rest of 2 MB left to the activity (which doesn't exist if I completely remove the WebView from the code). So it seems to have sth to do with the WebView itself. The same problem is mentioned here.

我还设置:

android:noHistory="true"

有有人对你的想法如何彻底的回到我ListActivity后摆脱了阅读新闻活动的内存使用?
很高兴听到任何想法,这是推动我疯了。有没有为Android手机提供超过16 MB堆大小的图表?

Has anyone of you an idea how to completely get rid of memory usage of the "NewsDetail" Activity after returning to my ListActivity? Would be glad to hear any ideas, this is driving me crazy. Is there a chart for Android phones providing more than 16 MB heap size?

推荐答案

我觉得它是一个已知的bug。请参阅本官方的http:// code。 google.com/p/android/issues/detail?id=2137

I think its a known bug. Please refer to this official http://code.google.com/p/android/issues/detail?id=2137

您可以参考此链接让人知道,这是一个已知的问题或如

you can refer to this link to let one know that this is a known issue or such

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

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