Skip to content

Commit

Permalink
fix: clean up target variables to avoid memory leaks (#6932)
Browse files Browse the repository at this point in the history
fix #6931
  • Loading branch information
fenduru authored and yyx990803 committed Oct 27, 2017
1 parent 4ad9a56 commit c355319
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 c355319

Please sign in to comment.