Skip to content

Commit

Permalink
improve docs to point to memory leak if ngOnDestroy is overridden in … (
Browse files Browse the repository at this point in the history
#4001)

Co-authored-by: Tim Deschryver <[email protected]>
  • Loading branch information
ValentinBossi and timdeschryver authored Aug 19, 2023
1 parent 745d91f commit 3e9022a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions projects/ngrx.io/content/guide/component-store/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<div class="alert is-important">

**Note:** If you override the `ngOnDestroy` method in your component store, you need to call `super.ngOnDestroy()`. Otherwise a memory leak may occur.

</div>

<code-example header="movies.store.ts">
@Injectable()
export class MoviesStore extends ComponentStore&lt;MoviesState&gt; implements OnDestroy {

constructor() {
super({movies: []});
}

override ngOnDestroy(): void {
// 👇 add this line
super.ngOnDestroy();
}
}
</code-example>

<code-example header="books-page.component.ts">
@Component({
// ... other metadata
Expand Down

0 comments on commit 3e9022a

Please sign in to comment.