Android -Webview内存泄漏
程序员文章站
2022-07-14 18:25:54
...
解决方案:
onDestory中加入如下代码,wvTerm是webview的id:
if (dataBinding?.wvTerm != null) {
val parent = dataBinding?.wvTerm?.parent
(parent as? ViewGroup)?.removeView(dataBinding?.wvTerm)
dataBinding?.wvTerm?.apply {
stopLoading()
settings.javaScriptEnabled = false
clearHistory()
removeAllViews()
try {
destroy()
} catch (e: Exception) {
}
}
}
上一篇: Java SE《基础篇》——(十)IO