Why does Chrome retain an anonymous MediaRecorder object in memory? Why does Chrome retain an anonymous MediaRecorder object in memory? google-chrome google-chrome

Why does Chrome retain an anonymous MediaRecorder object in memory?

This was confirmed to be an issue with Chromium (and by implication Google Chrome and probably other Chromium derivatives, including Electron):


At the time of writing this the issue is flagged as "available", which I presume communicates that it's acknowledged and effectively waiting for someone to step in and fix.

According to the specification:

A MediaStream object is said to be active when it has at least one MediaStreamTrack that has not ended. A MediaStream that does not have any tracks or only has tracks that are ended is inactive.

When you create a new MediaStream, unless you stop all its tracks, it remains in active state.

So, to unset this object, you need to explicitly get rid of its MediaStreamTrack objects, getting a reference to the stream e.g:

var myRecorder;navigator.mediaDevices.getUserMedia({   video: true,  audio: true}).then(function create_media_recorder(stream) {  myRecorder = new MediaRecorder(stream);  console.clear();});var myStream = myRecorder.stream;myStream.getTracks().forEach(function(el) {    el.stop()}

after that, you should see the recording icon going away - The media stream is now inactive.

Check these API's for further reference



Make sure you have "Preserve log upon navigation" unchecked in your browser's settings, otherwise console.clear() does nothing.



Also, I doubt this is a memory leak since unreachable objects are automatically removed. It's more likely MediaRecorder is saving objects to the global scope.


"4.3.1 Life-cycle and Media Flow" should clear things up a bit.