Skip to content

Commit

Permalink
fix(keep-alive): fix memory leak without breaking transition tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 7, 2023
1 parent 2632249 commit e0747f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/core/components/keep-alive.ts
Expand Up @@ -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) {
Expand All @@ -46,6 +51,7 @@ function pruneCache(
}
}
}
$vnode.componentOptions!.children = undefined
}

function pruneCacheEntry(
Expand Down
2 changes: 0 additions & 2 deletions src/core/vdom/create-component.ts
Expand Up @@ -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) {
Expand Down

0 comments on commit e0747f4

Please sign in to comment.