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

fix(router): prevent memory leaks by removing app references #2706

Merged
merged 15 commits into from Apr 12, 2019

Conversation

posva
Copy link
Member

@posva posva commented Apr 11, 2019

Fix #2639

Hey, @tmorehouse, I refactored the tests and reverted the code added to the if because I couldn't see why we would override the main app. Could you take a look please?

@tmorehouse
Copy link

I'll take a look here in a bit.

})

// main app previously initialized
// return as we don't need to set up new history listener
if (this.app) {
return
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this.app being set to null (if all apps are cleared out), this early return doesn't happen, and the code below it will be executed again.

Will that be an issue? IF so, maybe a flag needs to be set so that the following code is not executed a second time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this is called when a router is injected in a created component, it's only executed once per root instance

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't init get called for each app instance, as it is how the apps get added to this.apps array:

  init (app: any /* Vue component instance */) {
    process.env.NODE_ENV !== 'production' && assert(
      install.installed,
      `not installed. Make sure to call \`Vue.use(VueRouter)\` ` +
      `before creating root instance.`
    )

    this.apps.push(app)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but once per root instance

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, correct... so it should be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

[bug] Memory leak with this.$router.apps array and secondary apps on page being destroyed
2 participants