Skip to content

Commit

Permalink
fix(shareReplay): handle possible memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
josepot committed Dec 14, 2020
1 parent 1e1e022 commit 3e64f6b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/internal/operators/shareReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,17 @@ function shareReplayOperator<T>({
subject.complete();
},
});
if (isComplete) {
subscription = undefined;
}
} else {
innerSub = subject.subscribe(this);
}

this.add(() => {
refCount--;
innerSub.unsubscribe();
innerSub = undefined;
if (subscription && !isComplete && useRefCount && refCount === 0) {
subscription.unsubscribe();
subscription = undefined;
Expand Down

0 comments on commit 3e64f6b

Please sign in to comment.