From e0747f40a879b4000a1959d21377b51d1f1ed988 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 7 Dec 2023 17:07:15 +0800 Subject: [PATCH] fix(keep-alive): fix memory leak without breaking transition tests --- src/core/components/keep-alive.ts | 10 ++++++++-- src/core/vdom/create-component.ts | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/components/keep-alive.ts b/src/core/components/keep-alive.ts index 2bb2206b..b8215298 100644 --- a/src/core/components/keep-alive.ts +++ b/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( diff --git a/src/core/vdom/create-component.ts b/src/core/vdom/create-component.ts index d3a42eeb..9e48c575 100644 --- a/src/core/vdom/create-component.ts +++ b/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) {