Browse Source

remove parent/ref elm references when destroying instance, fix memory leak (fix vue-router#1279)

Evan You 9 years ago
parent
commit
3209f6f517
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/core/instance/lifecycle.js

+ 5 - 2
src/core/instance/lifecycle.js

@@ -119,6 +119,9 @@ export function lifecycleMixin (Vue: Class<Component>) {
     }
     }
     // call the last hook...
     // call the last hook...
     vm._isDestroyed = true
     vm._isDestroyed = true
+    // invoke destroy hooks on current rendered tree
+    vm.__patch__(vm._vnode, null)
+    // fire destroyed hook
     callHook(vm, 'destroyed')
     callHook(vm, 'destroyed')
     // turn off all instance listeners.
     // turn off all instance listeners.
     vm.$off()
     vm.$off()
@@ -126,8 +129,8 @@ export function lifecycleMixin (Vue: Class<Component>) {
     if (vm.$el) {
     if (vm.$el) {
       vm.$el.__vue__ = null
       vm.$el.__vue__ = null
     }
     }
-    // invoke destroy hooks on current rendered tree
-    vm.__patch__(vm._vnode, null)
+    // remove reference to DOM nodes (prevents leak)
+    vm.$options._parentElm = vm.$options._refElm = null
   }
   }
 }
 }