Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(devtools): avoid memory leak caused by devtools event buffer
fix #6591
  • Loading branch information
yyx990803 committed Sep 28, 2022
1 parent 551f606 commit 24f4c47
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/runtime-core/src/devtools.ts
Expand Up @@ -28,6 +28,7 @@ interface DevtoolsHook {
once: (event: string, handler: Function) => void
off: (event: string, handler: Function) => void
appRecords: AppRecord[]
_buffer: any[][]
}

export let devtools: DevtoolsHook
Expand Down Expand Up @@ -101,8 +102,26 @@ export const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook(
export const devtoolsComponentUpdated =
/*#__PURE__*/ createDevtoolsComponentHook(DevtoolsHooks.COMPONENT_UPDATED)

export const devtoolsComponentRemoved =
/*#__PURE__*/ createDevtoolsComponentHook(DevtoolsHooks.COMPONENT_REMOVED)
const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook(
DevtoolsHooks.COMPONENT_REMOVED
)

export const devtoolsComponentRemoved = (
component: ComponentInternalInstance
) => {
if (devtools && devtools._buffer.length) {
let wasBuffered = false
devtools._buffer = devtools._buffer.filter(item => {
if (item.some(arg => arg === component)) {
wasBuffered = true
return false
}
return true
})
if (wasBuffered) return
}
_devtoolsComponentRemoved(component)
}

function createDevtoolsComponentHook(hook: DevtoolsHooks) {
return (component: ComponentInternalInstance) => {
Expand Down

0 comments on commit 24f4c47

Please sign in to comment.