nauti nauti - 29 days ago 9
React JSX Question

Can a Redux store lead to a memory leak?

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 there.

But could that lead to a memory leak? Since Redux creates a new store every time the data changes and keeps the old ones. Would a ~2mb data every second pile up and crash the application?

The alternative I see is to keep the data in the local state (with setState).
I hope some more experienced React/Redux devs can advice me on this. Thanks!

Answer

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.