0

How to free up the memory that takes video when the source changes:

var video = document.querySelector('.video');
var nextButton = document.getElementById('next-button');
nextButton.addEventListener('click', function() {
    video.src = videoQueue.shift();
});
Dmitriy
  • 463
  • 1
  • 5
  • 12
  • 3
    The garbage collector should free up the memory automatically. – Barmar Jun 07 '19 at 15:58
  • Possible duplicate of [How to properly unload/destroy a VIDEO element](https://stackoverflow.com/questions/3258587/how-to-properly-unload-destroy-a-video-element) – Alexander Jun 07 '19 at 16:55

1 Answers1

0
var video = document.querySelector('.video');
var nextButton = document.getElementById('next-button');
nextButton.addEventListener('click', function() {
    video.removeAttribute("src");//This will clear memory
    video.load();//Refresh
});

I hope this helps.

Space
  • 39
  • 8
  • A quote from [this answer](https://stackoverflow.com/a/37632682/10967889) _the method video.load() causes unnecessary bandwidth to be used as it reloads the video from the server._ – weegee Jun 07 '19 at 16:03
  • I don’t quite understand why to use the load() method when adding the src video attribute without loading this method. video.setAttribute('src', videoQueue.shift()); – Dmitriy Jun 07 '19 at 16:14
  • tested this code, Safari issued a warning: "many memory resources are required" – Dmitriy Jun 07 '19 at 16:37
  • nextButton.addEventListener('click', function() { video.removeAttribute('src'); video.setAttribute('src', videoQueue.shift()); }); – Dmitriy Jun 07 '19 at 16:37