Can a Redux store lead to a memory leak?

前端 未结 4 2443
囚心锁ツ
囚心锁ツ 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:24

    Dan Abramov, the creator of Redux addresses this concern here like so:

    Note that sometimes people get confused about Redux and assume that on every action, the state tree has to be cloned deeply. This is absolutely not the case. Only the parts that changed need to change their references. For example, if an action causes a change to one item in an array, indeed, that item and the array will need to be copied, however, all other elements in the array will keep their identities. Because most of the times actions are very targeted and affect a few state keys, and because Redux encourages normalizing data so that the data structures are not deeply nested, this is much less of a problem for typical webapps than one might imagine.

    I think this is the meat of the answer.

提交回复
热议问题