reselect icon indicating copy to clipboard operation
reselect copied to clipboard

defaultMemoize leak the memory

Open gartz opened this issue 10 years ago • 2 comments

Hi, since the defaultMemoize will store the memoized data in a closure, it won't ever be collected, even if the original instance is lost and that code won't ever be reached. Would be better to use WeakMap and fallback to closure if it's not supported.

gartz avatar Sep 06 '16 23:09 gartz

I'm not sure I follow your thinking here. Would you expect this to leak memory?

const createSelector = require('reselect').createSelector

const generate = () => [...Array(100000).keys()]

while(true) {
  const state = { stuff: generate() }
  const mySelector = createSelector(state => state.stuff, stuff => stuff.map(x => x * 2))
  const values = mySelector(state)
}

ellbee avatar Sep 11 '16 12:09 ellbee

Closing due to inactivity

ellbee avatar Nov 13 '16 16:11 ellbee