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 memory leak #1507 #1552

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
11 changes: 9 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ function resetStore (store, hot) {
resetStoreVM(store, state, hot)
}

// helper function for resetStoreVM to prevent closure-preserving memory leak
export function getKeyFromVM (store, key) {
return function () {
return store._vm[key]
}
}

function resetStoreVM (store, state, hot) {
const oldVm = store._vm

Expand All @@ -257,10 +264,10 @@ function resetStoreVM (store, state, hot) {
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.
// using partial and getKeyFromVM to return functions with only arguments preserved in closure enviroment.
computed[key] = partial(fn, store)
Object.defineProperty(store.getters, key, {
get: () => store._vm[key],
get: getKeyFromVM(store, key),
enumerable: true // for local getters
})
})
Expand Down