-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
(programmatically added) destroyed hooks retain on new instances #10458
Comments
I wouldn't consider it a bug. You are modifying component's options before component's instance is created. If you need to programmatically add some lifecycle hook, you should do that in created() {
this.$on('hook:mounted', () => {
// do something when component is mounted
})
} And you don't have to worry about cleaning up the events added this way in beforeDestroy hook, Vue will handle it for you |
Very interesting, did not know this indeed. I had also asked this on Vue-land discord but unfortunately to no avail. |
You shouldn't write to |
Unfortunately a vue core team member told me on discord that So still looking for the official way to programmatically add lifecycle hooks. |
To clarify, writing to |
It's worth pointing out that the |
It turns out (as found by @Remcoman with this jsfiddle https://jsfiddle.net/c61xL8ar/2/) that the memory leak occurs on any programmatically added lifecycle hook if the component you are adding them to already list those lifecycle hooks. Ie in the updated jsfiddle the AComponent already has a mounted hook, the BComponent already has a created hook. Both are being retained now. @posva Does this mean its a bug or that we should use hook events anyway? |
Once again, that fiddle is paving over an object on |
@sirlancelot Please read this comment #10458 (comment) and read this vuejs/v2.vuejs.org#2247 Although I appreciate your time responding to this issue, there is conflicting information here and therefore I am asking the Vue core-team what I should do. |
Understandable. I was rather short in my previous post, and I apologize. I am going to guess that the "has workaround" was added in regards to using |
Hello, is there any way to use this workahound ( |
Version
2.6.10
Reproduction link
https://jsfiddle.net/h86atdq4/
Steps to reproduce
Open linked jsfiddle, open console and click toggle.
What is expected?
That the logged destroyed hook count is always 0 similar to the other hooks
What is actually happening?
The destroyed hook count keeps incrementing as it seems to retain hooks from already destroyed components
Note: I didnt check if this also happens with destroyed hook defined on the component itself
The text was updated successfully, but these errors were encountered: