Sunday, 18 December 2022

Video.js text tracks memory leak (WebVTT/VTT)

I use Video Text Tracks for displaying some advanced live info over the video.
Every few minutes a new video is loaded with its own .webvtt file (2-3k lines).

Everything works great except the fact that memory usage constantly increases.

It's a memory leak, for each new video additional VTTCue and TextTrack recordings are appended to the previous ones. enter image description here

Tried many things and ended up with the below approach, I'm out of ideas.

The tracks are added as proposed by the Video.js documentation (remote text tracks):

player.ready(() => {
  if (videoOptions.subtitles) {
    player.addRemoteTextTrack(
      {
        src: videoOptions.subtitles,
        kind: 'subtitles',
      },
      false,
    );
  }
});

And removed before the player dispose:

const remoteTextTracks = this.player.remoteTextTracks();
for (let i = remoteTextTracks.length - 1; i >= 0; i -= 1) {
  this.player.removeRemoteTextTrack(remoteTextTracks[i]);
}

They are successfully removed from the player but obviously kept in the memory.

How can I tell/direct/force the GC to completely remove old text tracks?



from Video.js text tracks memory leak (WebVTT/VTT)

No comments:

Post a Comment