-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Conversation
Prevents history listeners from being set up multiple times
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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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?