-
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
Ionic 4 - Memory leak of Pages via lifecycle event listeners #16285
Comments
I still observe this with Beta 16. With some of the Pages in our app having memory-heavy objects (such as a Are there any updates on this issue from the Ionic team? Thanks! |
Thank you so much, @manucorporat! I can't wait to try it out in the next release! 😀 |
This memory leak is still present in Beta 19, @manucorporat. 🙁 I know that changes were made to mitigate this, but it still seems to be an issue. Following the steps to reproduce in the OP still demonstrates the issue. Should this issue be re-opened or should I create a new one? Thank you very much! 🙂 |
Woop. I love the fixing of memory leaks 🍾 |
The leak pertaining to lifecycle event handlers appears to be fixed! 👍 Thanks so much, @manucorporat! 😀 |
Resolving the routes with resolvers is the biggest issue am I right? |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Bug Report
Ionic Info
Run
ionic info
from a terminal/cmd prompt and paste the output below.Describe the Bug
I think I'm observing a memory leak in
@ionic/angular
code that is holding onto a reference of aPage
instance.This is having a more significant impact in our enterprise app as it causes numeorus
Page
instances to leak even after thePage
has been destroyed. While I haven't been able to reproduce more than twoPage
instances leaking in a simple sample app, I've been able to reproduce what I believe is the cause of the leak in a vanilla starter template project.Steps to Reproduce
Steps to reproduce the behavior:
ionic start myLeak sidemenu --type=angular
.ionic serve
.List
and then clickHome
.Memory
tab.Collect garbage
button.Take heap snapshot
button.Class filter
search box typehomepage
to find leaking instances of theHomePage
.HomePage
node.HomePage
. Click on one of them. In theRetainers
window at the bottom there should be a retainer that traces throughangular-delegate.js:94
and__zone_symbol__ionViewWillEnterfalse in Detached HTMLElement
. You may need to expand and collapse objects in theRetainers
window or try the otherHomePage
instance to find it.Related Code
Follow the simple instructions in
Steps to Reproduce
to create a project that will reproduce the issue. Note theIonic Info
section for version info.Expected Behavior
I did not expect instances of the
HomePage
to leak due to a lingering reference.Additional Context
Using the file and line number info from the
Retainers
window (angular-delegate.js:94
), I investigated. The source of the leak may be in angular-delegate in thebindLifecycleEvents()
function where it is adding lifecycle-related event listeners which reference thePage
instance in the callback function. I did not see these listeners get removed by Ionic when leaving thePage
.I experimented by commenting out the body of
bindLifecycleEvents()
and that seemed to make the leak go away. I also hacked in unbinding the lifecycle events when leaving thePage
and that, too, seemed to make the leak go away.I think perhaps the issue may be due in part to the lifecycle event listener callback having a reference to the
Page
instance via a closure and that the event is not being unbound.Despite this issue, thank you for making a great framework! 😀
The text was updated successfully, but these errors were encountered: