Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(devtools): fix memory leak when devtools is not installed #4833

Merged
merged 2 commits into from Nov 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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