Skip to content
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

Closed
Barryrowe opened this issue Feb 18, 2016 · 5 comments
Closed

bug: NavPush Constructs @Page each Time. NeverDestroyed #5507

Barryrowe opened this issue Feb 18, 2016 · 5 comments
Assignees
Milestone

Comments

@Barryrowe
Copy link
Contributor

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.

@Ionitron Ionitron added the v2 label Feb 18, 2016
@Barryrowe
Copy link
Contributor Author

This was confirmed in alpha.54 and beta.0

@Barryrowe
Copy link
Contributor Author

It appears this might just be onPageWillUnload/onPageDidUnload not firing. If I add the OnDestroy ng2 hook, and implement ngOnDestroy, that does get called.

@adamdbradley adamdbradley self-assigned this Feb 18, 2016
@adamdbradley
Copy link
Contributor

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.

@Barryrowe
Copy link
Contributor Author

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.)
  }
}

@adamdbradley adamdbradley added this to the 2.0.0-beta.1 milestone Feb 18, 2016
@adamdbradley
Copy link
Contributor

Should be fixed in the next release, thanks!

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants