question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Safari leaks memory when videos are rapidly removed from the screen and re-added

See original GitHub issue

What happened and what did you expect to happen?

Safari has a problem with the HTMLVideoElement object that keeps leaking memory if there are many video elements that are being removed from the screen and re-attached back.

There is a similar bug reported in the WebKit bugzilla: https://bugs.webkit.org/show_bug.cgi?id=216820

At some point, Safari will show a message that the application is using significant memory. If it continues even further, Safari will crash.

Have you reviewed our existing documentation?

Reproduction steps

  1. Update the Meeting demo to render videos in smaller batches (such as with pagination).
  2. Open Activity Monitor.
  3. Join the demo with about 25 other video-enabled participants.
  4. Cycle through the pages.
  5. Notice that the memory keeps steadily rising without ever dropping back.

I’m able to confirm that this happens because RemoteVideo.tsx. If I comment the useEffect out so no video stream is attached, I cannot see any memory leaks.

Amazon Chime SDK React Components Library version

2.15.0

What browsers are you seeing the problem on?

MacOS Safari, iOS Safari

Browser version

14.1

Device Information

MacOS 11.6.4

Meeting and Attendee ID Information.

No response

Browser console logs

collaborate-ultra-log-1649082858254.log

Add any other context about the problem here.

Updating the RemoteVideo.tsx component’s useEffect to this seems to help but it does not eliminate the memory leaks completely. Perhaps there’s something else going on?

  React.useEffect(() => {
    if (!audioVideo || !videoEl.current) {
      return;
    }

    audioVideo.bindVideoElement(tileId, videoEl.current);
    const videoElement = videoEl.current;

    return () => {
      const tile = audioVideo.getVideoTile(tileId);

      if (tile) {
        audioVideo.unbindVideoElement(tileId);
      }

      if (videoElement) { // cleanup here
        videoElement.srcObject = null;
        videoElement.load();
      }
    };
  }, [audioVideo, tileId]);

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
devalevenkateshcommented, Apr 18, 2022

Created a demo using react component library which at an interval mounts and then un-mounts 25 RemoteVideo components tied to a single tileId.

Test Scenario Mount un-mount 25 remote video tiles and check for memory increase in Safari Timelines from developer tools also compare the same with Chrome devtools.

  1. Clear video srcObject tracks and then set the HTML video element’s srcObject to null.
  2. Directly set HTML video element’s srcObject to null without clearing any source tracks.
  3. Do nothing and keep as is the current code.
Clear video srcObject tracks and then set the srcObject to null Directly set srcObject to null Existing code
2-15-tracks-claenup-srcobject-null-safari 2-15-safari-srcobject-null 2-15-as-is-safari

Observations

  • From the graphs, it seems setting srcObject to null helps but clearing tracks and then setting it to null is the most memory efficient.
  • Chrome does not seem to differ with any approaches.

Few next questions

  1. My testing strategy may not be a good real world use-case hence wanted to understand your pagination flow and when RemoteVideo component mounts -> un-mounts?
  2. If using chooseRemoteVideoSources, when the new remote video sources are selected, do you keep the RemoteVideo’s from last render or you un-mount all the RemoteVideo’s and re-mount the RemoteVideo’s with the new tileId from current page’s attendeeIds?
  3. If yes, does it mean that there is no stopping of video happening anywhere and only RemoteVideo component mount/un-mount?
0reactions
devalevenkateshcommented, May 24, 2022

I am closing this issue since builders can install the JS SDK 3.1.0 or later on the latest component library 3.2.0. Newer release on component library is not needed. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Safari leaks memory when videos are rapidly removed from ...
Safari leaks memory when videos are rapidly removed from the screen and re-added.
Read more >
Safari is taking too much memory | Apple Developer Forums
Everything starts fine, but there must be a memory leak somewhere. Just after a few minutes, even with no activity in the browser...
Read more >
Detect and diagnose memory issues - WWDC21 - Videos
Discover how you can understand and diagnose memory performance problems with Xcode. We'll take you through the latest updates to Xcode's...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Fixed Computed details sidebar panel scrolling back to the top when <style> is added to page (255001@main); Fixed the DOM tree missing parts...
Read more >
iOS 16 - New Features - Apple
See all the latest features, enhancements, app updates, and more in iOS 16 for iPhone.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found