Memory Leak
blvz opened this issue ยท 3 comments
blvz commented
Line 36 in c2749aa
Example: https://jsfiddle.net/1zz9snkv/
fffixed commented
Jesus! You're really right bro! It's my big mistake!
blvz commented
No problem, mate. ๐
I did a implementation myself, if you wanna copy it:
Vue.mixin({
created () {
if (!this.$options.$bus) return
this.$busListeners = { }
Object.keys(this.$options.$bus).forEach(name => {
if (typeof this.$options.$bus[name] !== 'function') {
throw new Error(name + ' is not a function.')
}
const fn = this.$options.$bus[name].bind(this)
this.$busListeners[name] = fn
bus.$on(name, fn)
})
},
beforeDestroy () {
if (!this.$options.$bus) return
Object.keys(this.$options.$bus).forEach(name => {
const fn = this.$busListeners[name]
bus.$off(name, fn)
})
delete this.$busListeners
}
})
EDIT: oops, updated the above. I think it's better to store the listeners in a separate, $busListeners
object, to avoid conflicts with component's events.
fffixed commented
Tnx, Rafael, I fixed it ๐