From 3e64f6b06ad492de84f6636b5fb9b9b142b9b312 Mon Sep 17 00:00:00 2001 From: Josep M Sobrepere Date: Mon, 14 Dec 2020 11:25:10 +0100 Subject: [PATCH] fix(shareReplay): handle possible memory leaks --- src/internal/operators/shareReplay.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/internal/operators/shareReplay.ts b/src/internal/operators/shareReplay.ts index e8976b3c7d2..ee6a19712f1 100644 --- a/src/internal/operators/shareReplay.ts +++ b/src/internal/operators/shareReplay.ts @@ -108,6 +108,9 @@ function shareReplayOperator({ subject.complete(); }, }); + if (isComplete) { + subscription = undefined; + } } else { innerSub = subject.subscribe(this); } @@ -115,6 +118,7 @@ function shareReplayOperator({ this.add(() => { refCount--; innerSub.unsubscribe(); + innerSub = undefined; if (subscription && !isComplete && useRefCount && refCount === 0) { subscription.unsubscribe(); subscription = undefined;