WebView内存泄露

作者 mexican 日期 2017-06-21
WebView内存泄露

WebView内存无法释放解决办法

XML

<FrameLayout
android:id="@+id/web_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/web_progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@android:color/transparent"
android:indeterminateOnly="false"
android:visibility="visible"/>
</FrameLayout>

java

@Bind(R.id.web_container)
FrameLayout mContainer;
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_html);
ButterKnife.bind(this);
mWebView = new WebView(this);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
mWebView.setLayoutParams(lp);
mContainer.addView(mWebView, 0);
}
@Override
protected void onDestroy() {
super.onDestroy();
mContainer.removeAllViews();
mWebView.removeAllViews();
mWebView.destroy();
mWebView = null;
}