Memory leak while playing video in a WebView.

Moderators: odroid, mdrjr

Memory leak while playing video in a WebView.

Unread postby OverSoft » Fri Feb 17, 2017 4:55 pm

While using a webview inside our own app, the webview process continually starts using more and more memory while alternating (every 20 seconds or so) between:
a) showing a 1080p video (which uses the exynos video decoder) behind some divs with text
b) a page which contains no video.

Every 15 minutes (give or take) the ActivityManager reports this:
system_process I/ActivityManager: Low on memory:
system_process I/ActivityManager: MemInfo: 34,992K slab, 15,776K shmem, 27,964K vm alloc, 11,576K page tables 5,936K kernel stack
820K buffers, 165,836K cached, 77,344K mapped, 179,596K free
Free RAM: 268,908K
Used RAM: 96,244K
Lost RAM: 1,681,576K

The low memory message happens a couple of times before crashing the webview process.
I've enable out-of-process webviews to see if that changes behaviour, but this does not help.
I've also tried to destroy each WebView before recreating a new one, instead of using the same one continuously, this does not help either. (Not suprising, since it doesn't seem to spawn a new process on the machine, but keeps on using the same WebView process). Force-closing the app and restarting does help ofcourse, but this is obviously not the intended way to handle this.

Under Android 5.1.1, this just crashes the app within 15-minutes with a OOM error. Under Android 7.1 this takes a bit longer, but eventually also crashes the app (with the ActivityManager reports above still happening every 15 minutes).
We're able to reproduce it 100% of the time. We've tried Chrome as a Webview, but also the Android system webview and AOSP webview (compiled by myself).

We're also using the Odroid C2 on Android 5.1.1 and on this system, this crash does not occur, no matter how long we run the pages.

Alternating between these pages on stock Chrome also causes memory leaks and eventually a crash. But since we're using webviews in our app (and having to manually click play on every video), WebView's our primary concern.

The debug messages that most stand out to me are:
02-16 15:29:12.999 16578-23771/com.my.app.name W/cr_MediaCodecBridge: calling MediaCodec.release() on OMX.Exynos.AVC.Decoder
02-16 15:29:13.007 2945-23788/? W/libexynosv4l2: failed to ioctl: VIDIOC_DQBUF (22 - Invalid argument)
02-16 15:29:13.014 16578-23774/com.my.app.name E/BufferQueueProducer: [SurfaceTexture-55-16578-58] cancelBuffer: BufferQueue has been abandoned
(That last message is repeated 8 times with slightly changing timestamps)

It crashes with out of memory errors on Android 5.1.1.
It crashes without out of memory error on Android 7.1.


I'm able to quickly compile Android and WebView myself, so if i can assist in squating this bug, i'd love to help.
(In my limited understanding of the V4L2 subsystem, i think the video buffer isn't released properly while unloading the page containing the video, i've attached the full logcat while running under Android 7.1)
Attachments
logcat.txt
Logcat while running under 7.1 using Chrome as the WebView engine.
(1011.06 KiB) Downloaded 18 times
OverSoft
 
Posts: 10
Joined: Wed Feb 01, 2017 5:34 pm
languages_spoken: english
ODROIDs: C2, XU4

Re: Memory leak while playing video in a WebView.

Unread postby rooted » Fri Feb 17, 2017 11:03 pm

Are you using?

Code: Select all
webView.setWebChromeClient


And

Code: Select all
webView.setLayerType(View.LAYER_TYPE_HARDWARE)
User avatar
rooted
 
Posts: 3287
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1
C1+
C2
XU3 Lite
XU4
VU7+
HiFi Shield 2
Smart Power (original)

Re: Memory leak while playing video in a WebView.

Unread postby OverSoft » Tue Feb 28, 2017 5:20 am

Ofcourse i am. ;)
I have narrowed it down to something completely else and posted a bug report on the Chromium bugtracker.

https://bugs.chromium.org/p/chromium/issues/detail?id=694711
OverSoft
 
Posts: 10
Joined: Wed Feb 01, 2017 5:34 pm
languages_spoken: english
ODROIDs: C2, XU4

Re: Memory leak while playing video in a WebView.

Unread postby rooted » Tue Feb 28, 2017 6:00 am

I didn't know by your post how versed you were in Android development or how old the code is.

Good that you pinpointed a couple of problems and opened the bug report.
User avatar
rooted
 
Posts: 3287
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1
C1+
C2
XU3 Lite
XU4
VU7+
HiFi Shield 2
Smart Power (original)


Return to Android

Who is online

Users browsing this forum: No registered users and 2 guests