Skip to content

Commit

Permalink
fix: prevent memory leak due to circular reference in vnodes
Browse files Browse the repository at this point in the history
fix #6759
  • Loading branch information
yyx990803 committed Oct 9, 2017
1 parent 37533fd commit 405d8e9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/instance/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export function lifecycleMixin (Vue: Class<Component>) {
if (vm.$el) {
vm.$el.__vue__ = null
}
// release circular reference (#6759)
if (vm.$vnode) {
vm.$vnode.parent = null
}
}
}

Expand Down

4 comments on commit 405d8e9

@denonzhu
Copy link

Choose a reason for hiding this comment

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

这个并没有完全解决内存泄露问题,keeplive 包含复杂的的嵌套组件的时候,在组件被销毁后,其实内存还没有被清理

@denonzhu
Copy link

@denonzhu denonzhu commented on 405d8e9 Mar 2, 2019

Choose a reason for hiding this comment

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

目前我用这个能解决 但是会有兼容性问题

Vue.mixin({
    destroyed() {
        this.$el.remove()
        this.elm = null
        this.$el = null
        this.parent = null
        this.$parent = null
        this.options = null
        this.$options = null
        this.$vnode = null
        this._vnode = null
        this._watcher = null
        this._watchers = null
        this._computedWatchers = null
        this.$slots = null
        this.slots = null
        this.$scopedSlots = null
        this.scopedSlots = null
        this.$children = null
        this.children = null
        // this.store = null
        // this.$store = null
    }
})

@galiazzi
Copy link

@galiazzi galiazzi commented on 405d8e9 Mar 2, 2019 via email

Choose a reason for hiding this comment

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

@RichieChoo
Copy link

@RichieChoo RichieChoo commented on 405d8e9 Jan 19, 2021

Choose a reason for hiding this comment

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

目前我用这个能解决 但是会有兼容性问题

Vue.mixin({
    destroyed() {
        this.$el.remove()
        this.elm = null
        this.$el = null
        this.parent = null
        this.$parent = null
        this.options = null
        this.$options = null
        this.$vnode = null
        this._vnode = null
        this._watcher = null
        this._watchers = null
        this._computedWatchers = null
        this.$slots = null
        this.slots = null
        this.$scopedSlots = null
        this.scopedSlots = null
        this.$children = null
        this.children = null
        // this.store = null
        // this.$store = null
    }
})

兼容问题是什么?@denonzhu

Please sign in to comment.