Skip to content

Commit cb9986a

Browse files
parth67ktsn
authored andcommitted
fix: Memory leak happening while using registerModule/u… (#1508)
* Fixed issue#1507 : Memory leak happening while using registerModule/unregisterModule. * Adding comment for leak description. Simplyfy partial function to take only one argument. * Removed oldVm.computed = null. This statement is not required
1 parent b58d3d6 commit cb9986a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/store.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import applyMixin from './mixin'
22
import devtoolPlugin from './plugins/devtool'
33
import ModuleCollection from './module/module-collection'
4-
import { forEachValue, isObject, isPromise, assert } from './util'
4+
import { forEachValue, isObject, isPromise, assert, partial } from './util'
55

66
let Vue // bind on install
77

@@ -256,7 +256,9 @@ function resetStoreVM (store, state, hot) {
256256
const computed = {}
257257
forEachValue(wrappedGetters, (fn, key) => {
258258
// use computed to leverage its lazy-caching mechanism
259-
computed[key] = () => fn(store)
259+
// direct inline function use will lead to closure preserving oldVm.
260+
// using partial to return function with only arguments preserved in closure enviroment.
261+
computed[key] = partial(fn, store)
260262
Object.defineProperty(store.getters, key, {
261263
get: () => store._vm[key],
262264
enumerable: true // for local getters

src/util.js

+6
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ export function isPromise (val) {
6464
export function assert (condition, msg) {
6565
if (!condition) throw new Error(`[vuex] ${msg}`)
6666
}
67+
68+
export function partial (fn, arg) {
69+
return function () {
70+
return fn(arg)
71+
}
72+
}

0 commit comments

Comments
 (0)