Skip to content

Commit

Permalink
fix(devtools): fix memory leak when devtools is not installed (#4833)
Browse files Browse the repository at this point in the history
fix #4829
  • Loading branch information
caozhong1996 committed Nov 2, 2021
1 parent b5c0142 commit 6b32f0d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/runtime-core/src/devtools.ts
Expand Up @@ -33,10 +33,12 @@ export let devtools: DevtoolsHook

let buffer: { event: string; args: any[] }[] = []

let devtoolsNotInstalled = false

function emit(event: string, ...args: any[]) {
if (devtools) {
devtools.emit(event, ...args)
} else {
} else if (!devtoolsNotInstalled) {
buffer.push({ event, args })
}
}
Expand All @@ -56,7 +58,10 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
// clear buffer after 3s - the user probably doesn't have devtools installed
// at all, and keeping the buffer will cause memory leaks (#4738)
setTimeout(() => {
buffer = []
if (!devtools) {
devtoolsNotInstalled = true
buffer = []
}
}, 3000)
}
}
Expand Down

0 comments on commit 6b32f0d

Please sign in to comment.