溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

WebView顯示h5圖片并點(diǎn)擊放大過(guò)多后的內(nèi)存泄漏問(wèn)題

發(fā)布時(shí)間:2020-07-21 22:37:29 來(lái)源:網(wǎng)絡(luò) 閱讀:1272 作者:guozhendan 欄目:移動(dòng)開發(fā)

    最近在項(xiàng)目開發(fā)中用webview去顯示加載h6內(nèi)容,而h6內(nèi)容中有一些圖片,并且可以點(diǎn)擊放大看圖。在比較變態(tài)的測(cè)試方法(點(diǎn)擊圖片放大,關(guān)閉當(dāng)前界面,再進(jìn)入,再點(diǎn)擊圖片放大,大概10次左右)后,會(huì)導(dǎo)致圖片點(diǎn)擊沒(méi)反映了(其實(shí)就是webview內(nèi)存泄漏了)。錯(cuò)誤信息如下:

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 !!!


話不多說(shuō)了,直接分享一下解決方法吧!

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

2、在Activity的onDestroy時(shí),添加下面兩句話:

    customWebView.removeAllViews();

    customWebView.destroy();



向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI