From 3e9022a8e0b2e09c1c3b9285af9a2eec97db1719 Mon Sep 17 00:00:00 2001 From: Valentin Bossi Date: Sun, 20 Aug 2023 01:55:38 +0200 Subject: [PATCH] =?UTF-8?q?improve=20docs=20to=20point=20to=20memory=20lea?= =?UTF-8?q?k=20if=20ngOnDestroy=20is=20overridden=20in=20=E2=80=A6=20(#400?= =?UTF-8?q?1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> --- .../guide/component-store/lifecycle.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/projects/ngrx.io/content/guide/component-store/lifecycle.md b/projects/ngrx.io/content/guide/component-store/lifecycle.md index 37c09bd3ad..f673ef3d66 100644 --- a/projects/ngrx.io/content/guide/component-store/lifecycle.md +++ b/projects/ngrx.io/content/guide/component-store/lifecycle.md @@ -138,6 +138,27 @@ ComponentStore also implements the `OnDestroy` interface from `@angulare/core` t It also exposes a `destroy$` property on the ComponentStore class that can be used instead of manually creating a `Subject` to unsubscribe from any observables created in the component. +
+ +**Note:** If you override the `ngOnDestroy` method in your component store, you need to call `super.ngOnDestroy()`. Otherwise a memory leak may occur. + +
+ + +@Injectable() +export class MoviesStore extends ComponentStore<MoviesState> implements OnDestroy { + + constructor() { + super({movies: []}); + } + + override ngOnDestroy(): void { + // 👇 add this line + super.ngOnDestroy(); + } +} + + @Component({ // ... other metadata