Skip to content

Commit 9c87635

Browse files
thekibaKwintenP
authored andcommitted
content(rxjs): avoid memory leaks
Use `publishReplay` and `refCount` instead of `shareReplay` to avoid memory leaks. See ReactiveX/rxjs#3336
1 parent d7486be commit 9c87635

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

content/rxjs/use-ngifas.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ We can also make our Observable hot so that the Observable will no longer trigge
7272

7373
This fixes our problem because it means it doesn't matter anymore if we have multiple subscriptions.
7474

75-
To do this, we can use for example the `shareReplay` operator.
75+
To do this, we can use for example the `publishReplay` and `refCount` operators.
7676

7777
```ts
7878
@Component({
@@ -81,7 +81,8 @@ To do this, we can use for example the `shareReplay` operator.
8181
})
8282
export class SomeComponent implements OnInit, OnDestroy {
8383
sharedData$ = data$.pipe(
84-
shareReplay(1)
84+
publishReplay(1),
85+
refCount()
8586
);
8687
...
8788
}

0 commit comments

Comments
 (0)