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

animationFrames() has memory leak. #6946

Open
C-zhui opened this issue Apr 24, 2022 · 3 comments
Open

animationFrames() has memory leak. #6946

C-zhui opened this issue Apr 24, 2022 · 3 comments

Comments

@C-zhui
Copy link

C-zhui commented Apr 24, 2022

Describe the bug

animationFrames will add subscriptions again again before unsubscribe.

Expected behavior

Here I describe the problem.
I can't find the logic of removing sub subscription inside animationFrames.
So I add this to source code in Subscription class.
image
Add this to project code.
image
You will see this.
image
Shouldn't they be removed from array:this._finalizers over time???

Reproduction code

As shown in the prev section.

Reproduction URL

No response

Version

7.5.5

Environment

No response

Additional context

No response

@C-zhui C-zhui changed the title animationFrame() has memory leak. animationFrames() has memory leak. Apr 24, 2022
@ajafff
Copy link
Contributor

ajafff commented Apr 24, 2022

I can confirm that it accumulates a new Subscription for each animation frame. The Subscriptions returned from animationFrameProvider.schedule are never closed/unsubscribed, therefore they are not removed from the list of finalizers.

I tried fixing this, but I don't know which is the preferred solution:

  • don't collect all subscriptions in a parent subscription in animationFramesFactory, instead save the latest subscription in a local variable and return a finalizer function that unsubscribes from that subscription
  • in animationFrameProvider.schedule, unsubscribe from the returned subscription after calling the callback
  • don't use animationFrameProvider.schedule at all, because creating a Subscription for every invocation seems unnecessary (wasteful and complex). instead just use animationFrameProvider.requestAnimationFrame

@DavidWeiss2
Copy link

In my opinion:

  • in animationFrameProvider.schedule, unsubscribe from the returned subscription after calling the callback

@icoco
Copy link

icoco commented Jan 7, 2025

have to hard code to free ? question : #7523

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

No branches or pull requests

4 participants