-
Notifications
You must be signed in to change notification settings - Fork 3k
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
shareReplay memory leak #5034
Comments
I suppose the |
After playing with what you suggested these are my observations:
|
I suggested the wrong place. Try setting rxjs/src/internal/operators/shareReplay.ts Line 105 in ffb4b0b
And set |
There's an explanation here: https://ncjamieson.com/whats-changed-with-sharereplay/ |
Thanks that helped. |
Do you want to submit a PR for the change? |
Actually, if it's the rxjs/src/internal/Subscription.ts Lines 63 to 66 in b713d39
E.g.: this._parentOrParents = null;
// null out _subscriptions first so any child subscriptions that attempt
// to remove themselves from this subscription will noop
this._subscriptions = null;
this._unsubscribe = null; Can you verify whether or not that solves the problem - with the changes made to the |
By the way, setting |
No worries. I'll build your repro project and will have a poke around on the weekend. Thinking about it again, the Feel free to open a PR with the fix. I'll verify it once I build your repro, etc. Thanks for finding, reporting and continuing to investigate this. It's appreciated! |
The subscription needs to be cleared to prevent the implementation holding a reference to the completed source. In Angular, not clearing the reference can lead to components not being garbage collected. Closes ReactiveX#5034
The subscription needs to be cleared to prevent the implementation holding a reference to the completed source. In Angular, not clearing the reference can lead to components not being garbage collected. Closes ReactiveX#5034
I hit this issue recently. Wondering if this is still being considered, or if there are recommended workarounds? Sorry for the un-educated question. Still trying to get my head around all the rxjs paradigm. |
The subscription needs to be cleared to prevent the implementation holding a reference to the completed source. In Angular, not clearing the reference can lead to components not being garbage collected. Closes ReactiveX#5034
The subscription needs to be cleared to prevent the implementation holding a reference to the completed source. In Angular, not clearing the reference can lead to components not being garbage collected. Closes ReactiveX#5034
The workaround for now is:
|
The subscription needs to be cleared to prevent the implementation holding a reference to the completed source. In Angular, not clearing the reference can lead to components not being garbage collected. Closes #5034
Bug Report
Current Behavior
After component gets destroyed, its reference stays alive, because the fact that I subscribe to bigger scoped Observable (for example route.params) and switch it (via switchMap) to the Observable piped with shareReplay operator.
After taking heap snapshots via chrome devtools, I noticed that reference retainers mentioned shareReplay operator. If I use publishReplay and refCount instead of shareReplay problem is fixed, that's why I think shareReplay has an issue.
Please have a look at code on GitHub and screen shots for better understanding the issue. (Code explains issue better than description). You can see code sample below.
Event after reviewing #3336, issue still remains with shareReplay.
Reproduction
Expected behavior
After person component gets destroyed (for example, via navigation) it should be picked up by garbage collector and no reference of it should exist in the application.
Environment
Possible Solution
To fix the issue instead of shareReplay use
Additional context/Screenshots (Heap Snapshots)
This is what happens when I open the application on the home page, navigate to person page and then back to home page (I click garbage collection several times and take heap snapshot). Person component got destroyed but reference still lives in the heap. Under retainers you can spot shareReplay operator.
This is what happens when I navigate between home and person components several times and ending on person component. 2 references of it exists in the application.
None of these issues exist when using
publishReplay(1), refCount()
.The text was updated successfully, but these errors were encountered: