Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few memory leaks while tearing down the player #5698

Merged
merged 2 commits into from
Sep 15, 2024

Conversation

absidue
Copy link
Member

@absidue absidue commented Sep 13, 2024

Fix a few memory leaks while tearing down the player

Pull Request Type

  • Bugfix

Description

This pull request addresses two current memory leaks that occur while tearing down the player or more specifically two things that don't get torn down at the moment.

The first issue is that shaka-player's component registrations are global, however as we create our custom components with references to variables that are only meant to be used for the current player session, we need to clean those registrations up otherwise it will prevent the variables in question from being garbage collected until you play another video. Unfortunately shaka-player doesn't have a way to unregister a component, so I decided to overwrite the registration with null.

The second issue is that shaka-player's destroy() method is asynchronous, however as Vue's lifecycle hooks are synchronous, it means that the destroy() method isn't finished by the time FreeTube and Vue consider the player to be destroyed. To solve that I decided to introduce a method to the ft-shaka-video-player component which calls the destroy method on shaka-player. That way we can destroy the player first, wait for it to be finished and then prodeed with unmounting the Vue component.

This doesn't fix all of the problems, as shaka-player doesn't fully clean up after itself, hopefully some of their recent pull requests will help with that and I've also opened an issue about some of the UI elements not getting removed properly. Additionally there are some other things that seem to hang around (according to the Memory tab in the devtools), but I'm not sure why, my guess is that it is a Vue 2 bug, if that is the case then the only solution is updating to Vue 3.

Desktop

  • OS: Windows
  • OS Version: 10
  • FreeTube version: c90674d

Additional context

There may be code conflicts between this pull request and #5677, in which case please make sure that pull request is merged first.

@github-actions github-actions bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Sep 13, 2024
@FreeTubeBot FreeTubeBot enabled auto-merge (squash) September 13, 2024 22:10
PikachuEXE
PikachuEXE previously approved these changes Sep 15, 2024
Copy link
Collaborator

@PikachuEXE PikachuEXE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last guy remember to merge after shaka player PR merged~

This comment was marked as resolved.

@github-actions github-actions bot removed the PR: waiting for review For PRs that are complete, tested, and ready for review label Sep 15, 2024
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

@FreeTubeBot FreeTubeBot merged commit 5012498 into FreeTubeApp:development Sep 15, 2024
5 checks passed
@absidue absidue deleted the player-memory-leaks branch September 15, 2024 22:19
PikachuEXE added a commit to PikachuEXE/FreeTube that referenced this pull request Sep 16, 2024
* development: (29 commits)
  Translated using Weblate (Flemish (West))
  Added translation using Weblate (Flemish (West))
  Translated using Weblate (Slovak)
  Improve history import performance and fix some bugs (FreeTubeApp#5666)
  Bump electron from 32.0.2 to 32.1.0 (FreeTubeApp#5710)
  Local API: Use IOS HLS manifest for livestreams (FreeTubeApp#5705)
  Translated using Weblate (Slovak)
  Translated using Weblate (Japanese)
  Bump the stylelint group with 2 updates (FreeTubeApp#5706)
  Bump swiper from 11.1.12 to 11.1.14 (FreeTubeApp#5709)
  Fix a few memory leaks while tearing down the player (FreeTubeApp#5698)
  Fix audio track selection (FreeTubeApp#5697)
  Bump shaka-player from 4.10.12 to 4.11.1 (FreeTubeApp#5677)
  Translated using Weblate (Czech)
  Translated using Weblate (Serbian)
  Translated using Weblate (Polish)
  Translated using Weblate (German)
  Translated using Weblate (Chinese (Simplified Han script))
  Bump express from 4.19.2 to 4.20.0 (FreeTubeApp#5687)
  Translated using Weblate (Turkish)
  ...
PikachuEXE added a commit to PikachuEXE/FreeTube that referenced this pull request Sep 16, 2024
* development: (74 commits)
  Translated using Weblate (Flemish (West))
  Added translation using Weblate (Flemish (West))
  Translated using Weblate (Slovak)
  Improve history import performance and fix some bugs (FreeTubeApp#5666)
  Bump electron from 32.0.2 to 32.1.0 (FreeTubeApp#5710)
  Local API: Use IOS HLS manifest for livestreams (FreeTubeApp#5705)
  Translated using Weblate (Slovak)
  Translated using Weblate (Japanese)
  Bump the stylelint group with 2 updates (FreeTubeApp#5706)
  Bump swiper from 11.1.12 to 11.1.14 (FreeTubeApp#5709)
  Fix a few memory leaks while tearing down the player (FreeTubeApp#5698)
  Fix audio track selection (FreeTubeApp#5697)
  Bump shaka-player from 4.10.12 to 4.11.1 (FreeTubeApp#5677)
  Translated using Weblate (Czech)
  Translated using Weblate (Serbian)
  Translated using Weblate (Polish)
  Translated using Weblate (German)
  Translated using Weblate (Chinese (Simplified Han script))
  Bump express from 4.19.2 to 4.20.0 (FreeTubeApp#5687)
  Translated using Weblate (Turkish)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants