rxjs
rxjs copied to clipboard
animationFrames() has memory leak.
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.
Add this to project code.
You will see this.
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
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.scheduleat all, because creating a Subscription for every invocation seems unnecessary (wasteful and complex). instead just useanimationFrameProvider.requestAnimationFrame
In my opinion:
- in
animationFrameProvider.schedule, unsubscribe from the returned subscription after calling the callback