Can a Redux store lead to a memory leak?

前端 未结 4 2469
囚心锁ツ
囚心锁ツ 2021-02-20 00:55

I have a dashboard application with several charts getting updated on a set interval. My first thought was to update the data in the store and then let all charts feed from ther

4条回答
  •  野的像风
    2021-02-20 01:28

    "Since Redux creates a new store every time the data charges and keeps the old ones."

    Vanilla Redux does not do that, or every Redux store would leak. As it is, the rest of your application holding reference to the state will prevent it from being cleaned up.

    Eg something like

    window.states = []
    store.subscribe(() => {
      window.states.push(store.getState())
    })
    

    Will cause unbounded memory growth.

    Also, some Redux development tools do leak to provide time travel capabilities, so be sure they are turned off for your production build.

提交回复
热议问题