Skip to content

Commit

Permalink
fix: clean up target variables to avoid memory leaks (vuejs#6932)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenduru authored and hefeng committed Jan 25, 2019
1 parent da40d42 commit 42228cc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/instance/events.js
Expand Up @@ -19,7 +19,7 @@ export function initEvents (vm: Component) {
}
}

let target: Component
let target: any

function add (event, fn, once) {
if (once) {
Expand All @@ -40,6 +40,7 @@ export function updateComponentListeners (
) {
target = vm
updateListeners(listeners, oldListeners || {}, add, remove, vm)
target = undefined
}

export function eventsMixin (Vue: Class<Component>) {
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/web/runtime/modules/events.js
Expand Up @@ -26,7 +26,7 @@ function normalizeEvents (on) {
}
}

let target: HTMLElement
let target: any

function createOnceHandler (handler, event, capture) {
const _target = target // save current target element in closure
Expand Down Expand Up @@ -78,6 +78,7 @@ function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
target = vnode.elm
normalizeEvents(on)
updateListeners(on, oldOn, add, remove, vnode.context)
target = undefined
}

export default {
Expand Down
1 change: 1 addition & 0 deletions src/platforms/weex/runtime/modules/events.js
Expand Up @@ -46,6 +46,7 @@ function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
const oldOn = oldVnode.data.on || {}
target = vnode.elm
updateListeners(on, oldOn, add, remove, vnode.context)
target = undefined
}

export default {
Expand Down

0 comments on commit 42228cc

Please sign in to comment.