浏览代码

fix(keep-alive): fix memory leak without breaking transition tests

Evan You 2 年之前
父节点
当前提交
e0747f40a8
共有 2 个文件被更改,包括 8 次插入4 次删除
  1. 8 2
      src/core/components/keep-alive.ts
  2. 0 2
      src/core/vdom/create-component.ts

+ 8 - 2
src/core/components/keep-alive.ts

@@ -33,10 +33,15 @@ function matches(
 }
 
 function pruneCache(
-  keepAliveInstance: { cache: CacheEntryMap; keys: string[]; _vnode: VNode },
+  keepAliveInstance: {
+    cache: CacheEntryMap
+    keys: string[]
+    _vnode: VNode
+    $vnode: VNode
+  },
   filter: Function
 ) {
-  const { cache, keys, _vnode } = keepAliveInstance
+  const { cache, keys, _vnode, $vnode } = keepAliveInstance
   for (const key in cache) {
     const entry = cache[key]
     if (entry) {
@@ -46,6 +51,7 @@ function pruneCache(
       }
     }
   }
+  $vnode.componentOptions!.children = undefined
 }
 
 function pruneCacheEntry(

+ 0 - 2
src/core/vdom/create-component.ts

@@ -62,8 +62,6 @@ const componentVNodeHooks = {
       vnode, // new parent vnode
       options.children // new children
     )
-    // #12187 unset children reference after use to avoid memory leak
-    options.children = undefined
   },
 
   insert(vnode: MountedComponentVNode) {