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.
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())
I'm starting the article Activity via:
Intent i = new Intent(getApplicationContext(), NewsDetail.class);
i.putExtra("position", position);
startActivity(i);
After reading this question, I changed my Layout so that I add the WebView programmatically:
newsDetail = new WebView(getApplicationContext());
In my onDestroy method is set:
public void onDestroy(){
super.onDestroy();
newsDetail.destroy();
newsDetail = null;
finish();
System.gc();
}
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. :/
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.
I also set:
android:noHistory="true"
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?