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!
DEFINITION A memory leak is the gradual deterioration of system performance that occurs over time as the result of the fragmentation of a computer's RAM due to poorly designed or programmed applications that fail to free up memory segments when they are no longer needed.
First, in terms of raw memory usage, Redux is no different than any other JavaScript library.
What is the redux store? In an object that stores the state tree of the app, this data is saved while are in the same tag session, if you refresh the tag of your browser all the state tree restarts, so all the info before is no longer in memory.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With