-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: NavPush Constructs @Page each Time. NeverDestroyed #5507
Comments
This was confirmed in alpha.54 and beta.0 |
It appears this might just be onPageWillUnload/onPageDidUnload not firing. If I add the OnDestroy ng2 hook, and implement ngOnDestroy, that does get called. |
The onPageWillUnload/DidUnload is probably a bug and I'll look into it. However, if you got to Page1, then push to Page2, then push to Page1 again, it will create a new instance of Page1, and this is by design and similar to how native apps works. If you want to use the same instance then you would pop back to the first instance of Page1. As for the lifecycles i'll take a look, thanks for the report. |
Thanks, that makes sense. It does look like it's just not firing the Unload events. For anyone running into this that needs the "Will/DidUnload" hooks, you can do the following instead for now: import {OnDestroy} from "angular2/core";
@Page(...)
export class MyPage{
//...
ngOnDestroy(){
//do your unload logic here (unsubscribe from streams, etc.)
}
} |
Should be fixed in the next release, thanks! |
Type: bug
Ionic Version: 2.x
Platform: all
When an @page component is navigated too via a NavController.push or .setRoot, a new Instance of the component is created (it's constructor() fires). However, when the page is navigated away from, it is never destroyed (onPageWillUnload and onPageDidUnload never fire). The next time you navigate to the same type of component, another new instance is created, rather than re-using the instance that has never been disposed.
If the intention is that a new instance should be created each time, it needs to be disposed properly, or there is a memory leak issue.
If the intention is that a single instance should be created and re-used when the type is navigated too, then this is currently broken.
The text was updated successfully, but these errors were encountered: