HTML video leak memory when constantly change the source with JavaScript

UNCONFIRMED
Unassigned

Status

()

Core
Audio/Video: Playback
P3
normal
UNCONFIRMED
2 years ago
2 years ago

People

(Reporter: Milestone Systems, Unassigned)

Tracking

42 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [memshrink:P2])

Attachments

(3 attachments)

(Reporter)

Description

2 years ago
User Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36

Steps to reproduce:

1. Create two video elements and attach them in DOM using JavaScript
2. Add canplay and play event listeners to the one of the video elements (I will call it buffer)
3. Add a source to the buffer video element
4. When canplay event is fired play the video
5. When play event is fired swap both video elements, remove canplay and play event listeners from buffer video element and load a new source to it.
6. Repeat steps 1 to 5 twenty times.


Actual results:

Memory usage increase continuously.


Expected results:

Memory usage should be stable.
(Reporter)

Comment 1

2 years ago
Working prototype can be found here: http://download.milestonesys.com/14122015tvh/leak.html

Comment 2

2 years ago
I tested with FF42 on Win 7, the RAM use is fine, but the CPU use spikes to 75%!
(Reporter)

Comment 3

2 years ago
I have noticed that when started in safe mode there is no leaking of memory but the CPU load is very high.

Updated

2 years ago
Component: Untriaged → Audio/Video
Product: Firefox → Core
Safe mode not leaking is interesting...  Perhaps related to use of HW decoders/GMP?
Component: Audio/Video → Audio/Video: Playback
Whiteboard: [memshrink]

Comment 5

2 years ago
Reporter, can you attach a memory log in normal mode and in safe mode (both with a fresh profile https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles).
To save memory log, type about:memory in the location bar, measure and save.
Flags: needinfo?(browser_defects)
(Reporter)

Comment 6

2 years ago
Created attachment 8703546 [details]
Running 40 minutes with clear profile memory snapshot. Memory increase from 480 to 920 MB
Flags: needinfo?(browser_defects)
(Reporter)

Comment 7

2 years ago
Created attachment 8703547 [details]
Running 80 minutes in safe mode with clear profile memory snapshot. Memory increase from 300 to 350 MB
Go to about:memory and click on "Minimize memory usage". Does this free up the memory?
The first memory report file looks unusual:

> 88.66 MB (100.0%) -- explicit
>
> 1,048.36 MB ── private
>   977.60 MB ── resident

explicit is really low but private and resident are high. So our internal measurements are clearly missing some significant source of memory usage... which suggests something gfx related :/
I tried the test from comment 1 on Linux. CPU usage went up to 450% but memory usage was fairly stable around 300 MiB (both e10s and non-e10s).
On Windows, the WMF decoder typically keeps up to 30 decoded frames internally.

This video is 352x288 at 8fps, we have 40 decoders. Each frame will be 152kB, and there are 8 of them per video.

so 152kB * 8 * 40 = 48MB for the frames themselves, that could easily be doubled as we have the compositor having a copy to paint them while we're decoding some more.
Each decoder takes a fair amount of memory: we have the entire context, task queue, the lot.
I'm not particularly concerned with 300MB usage.

CPU usage is very high, but this may be related to bug 1239899.
Priority: -- → P2
Can you selectively re-enable your add-ons to help determine which one is causing the high memory usage?
Flags: needinfo?(browser_defects)
Safe mode also turns off hardware acceleration, we think, so you could also try disabling that and see if it helps. We've seen many cases where particular graphics drivers use a lot of memory.
(Reporter)

Comment 14

2 years ago
I tried another long running test overnight without Safe mode but no add-ons enabled. The result in the morning was 2,8 GB memory consumption and all frozen picture. I tried to get memory profile snapshot but then FF crashed. Version used was 44.
Flags: needinfo?(browser_defects)
Whiteboard: [memshrink] → [memshrink:P2]
(Reporter)

Comment 15

2 years ago
Another long running test ( 9 hours ) with FF 44, no add-ons, no hardware acceleration, memory remains stable at just under 400 MB. CPU usage is very high at close to 100% on i7-4810MQ but I guess this is to be expected. 
The leak is confirmed with hardware acceleration on both Intel and NVidia video cards - both with latest drivers.
I cannot reproduce this leak on trunk (non-e10s, although playing the videos seems to start a plugin-container process?) with the URL listed in comment 1.  Memory usage while playing the videos is stable at ~450MB over the course of an hour (lower for the main process, higher for the plugin process).  The machine is Windows 7 with an integrated Intel graphics card; about:support for graphics says:

Adapter Description	Intel(R) HD Graphics 5500
Adapter Drivers	igdumdim64 igd10iumd64 igd10iumd64 igdumdim32 igd10iumd32 igd10iumd32
Adapter RAM	Unknown
Asynchronous Pan/Zoom	wheel input enabled; touch input enabled
Device ID	0x1616
Direct2D Enabled	true
DirectWrite Enabled	true (6.3.9600.18123)
Driver Date	4-29-2015
Driver Version	10.18.14.4206
GPU #2 Active	false
GPU Accelerated Windows	1/1 Direct3D 11 (OMTC)
Subsys ID	222617aa
Supports Hardware H264 Decoding	Yes
Vendor ID	0x8086
WebGL Renderer	Google Inc. -- ANGLE (Intel(R) HD Graphics 5500 Direct3D11 vs_5_0 ps_5_0)
windowLayerManagerRemote	true
AzureCanvasBackend	direct2d 1.1
AzureContentBackend	direct2d 1.1
AzureFallbackCanvasBackend	cairo
AzureSkiaAccelerated	0

I'm unsure whether my drivers are the newest possible or not.  I will try other versions to see if I can reproduce the problem.

What does the graphics section of about:support say for you?
Flags: needinfo?(browser_defects)
I have a 44b1 browser that's been running the webpage in comment 1 for ~45 minutes, same about:support output (no H264 decoding, because "too many DXA videos playing").  The memory according to Task Manager does appear to be going up somewhat (steady at ~300MB at the start, now around ~330-350MB).  An about:memory report shows nothing out of the ordinary.  I'll let it play for another hour or two and take an about:memory snapshot.
(In reply to Nathan Froyd [:froydnj] from comment #17)
> I have a 44b1 browser that's been running the webpage in comment 1 for ~45
> minutes, same about:support output (no H264 decoding, because "too many DXA
> videos playing").  The memory according to Task Manager does appear to be
> going up somewhat (steady at ~300MB at the start, now around ~330-350MB). 
> An about:memory report shows nothing out of the ordinary.  I'll let it play
> for another hour or two and take an about:memory snapshot.

The memory usage is unchanged.  As a result, I don't think an about:memory snapshot would be helpful.
(Reporter)

Comment 19

2 years ago
Created attachment 8763514 [details]
about_support.zip

Attached is the about:support that was requested.
(Reporter)

Comment 20

2 years ago
Information provided in attachment 8763514 [details]
Flags: needinfo?(browser_defects)
Mass change P2 -> P3
Priority: P2 → P3
You need to log in before you can comment on or make changes to this bug.