WebView显示h5图片并点击放大过多后的内存泄漏问题

发布时间:2020-07-21 22:37:29 作者:guozhendan
来源:网络 阅读:1274

    最近在项目开发中用webview去显示加载h6内容,而h6内容中有一些图片,并且可以点击放大看图。在比较变态的测试方法(点击图片放大,关闭当前界面,再进入,再点击图片放大,大概10次左右)后,会导致图片点击没反映了(其实就是webview内存泄漏了)。错误信息如下:

12-02 10:46:19.824: E/Surface(19632): dequeueBuffer failed (Invalid argument)

12-02 10:46:19.824: E/ViewRootImpl(19632): Could not lock surface

12-02 10:46:19.824: E/ViewRootImpl(19632): java.lang.IllegalArgumentException

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.Surface.nativeLockCanvas(Native Method)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.Surface.lockCanvas(Surface.java:244)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2474)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2448)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2292)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1922)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1039)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5648)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.Choreographer.doCallbacks(Choreographer.java:574)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.Choreographer.doFrame(Choreographer.java:544)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.os.Handler.handleCallback(Handler.java:733)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.os.Handler.dispatchMessage(Handler.java:95)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.os.Looper.loop(Looper.java:136)

12-02 10:46:19.824: E/ViewRootImpl(19632): at android.app.ActivityThread.main(ActivityThread.java:5047)

12-02 10:46:19.824: E/ViewRootImpl(19632): at java.lang.reflect.Method.invokeNative(Native Method)

12-02 10:46:19.824: E/ViewRootImpl(19632): at java.lang.reflect.Method.invoke(Method.java:515)

12-02 10:46:19.824: E/ViewRootImpl(19632): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

12-02 10:46:19.824: E/ViewRootImpl(19632): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)

12-02 10:46:19.824: E/ViewRootImpl(19632): at dalvik.system.NativeStart.main(Native Method)

12-02 10:46:19.834: E/JavaBinder(19632): !!! FAILED BINDER TRANSACTION !!!


话不多说了,直接分享一下解决方法吧!

1、在初始化时,customWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

2、在Activity的onDestroy时,添加下面两句话:

    customWebView.removeAllViews();

    customWebView.destroy();



推荐阅读:
  1. 点击图片放大至原始图片大小
  2. android listview item点击后,显示点击效果

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android webview

上一篇:看完这个,你觉得你真的懂快速排序吗?

下一篇:移动化维修工单管理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》