hi,
I am having troubles with unsubscribing Events in app.component.ts after closing the app.
In the constructor of app.component I subscribe to some Events like changing the current Page. If the User closes the app I want to unsubscribe to all Events to avoid memory leaks.
I already tried to handle this through the ionic lifecycle Events, but none of them fires after closing the app.
Any idea I handle this?
1 Like
Does anyone have an answer?
Use OnDestroy
:
import { OnInit, OnDestroy } from '@angular/core';
export class AppComponent implements OnInit, OnDestroy {
...
public ngOnInit() {
this.logger.info('AppComponent: ngOnInit()');
// subscribe to things
}
public ngOnDestroy() {
this.logger.info('AppComponent: ngOnDestroy()');
// unsubscribe from things
}
}
1 Like
Thanks!
Is it possible to unsubscribe from all events at once
Or should it be for each event specifically?
Yes, that’s my understanding.
1 Like