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

Fixed issue#1507 : Memory leak happening while using registerModule/u… #1508

Merged
merged 3 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ function resetStoreVM (store, state, hot) {
const computed = {}
forEachValue(wrappedGetters, (fn, key) => {
// use computed to leverage its lazy-caching mechanism
// direct inline function use will lead to closure preserving oldVm.
// using partial to return function with only arguments preserved in closure enviroment.
computed[key] = partial(fn, store)
parth67 marked this conversation as resolved.
Show resolved Hide resolved
Object.defineProperty(store.getters, key, {
get: () => store._vm[key],
Expand Down Expand Up @@ -289,7 +291,7 @@ function resetStoreVM (store, state, hot) {
oldVm._data.$$state = null
})
}
Vue.nextTick(() => oldVm.$destroy())
Vue.nextTick(() => { oldVm.$destroy(); oldVm.computed = null })
parth67 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export function assert (condition, msg) {
if (!condition) throw new Error(`[vuex] ${msg}`)
}

export function partial (fn, ...bindargs) {
return function (...callargs) {
return fn(...bindargs, ...callargs)
export function partial (fn, arg) {
return function () {
return fn(arg)
}
}