简体   繁体   中英

How does redux garbage collection work?

How exactly does redux garbage collection work. We all know that redux promotes immutability. So what happens to the stale state instances? For example in my reducer if i have a case such as:

...
case 'MY_ACTION':
     return state.set('name', action.name)
... 

Now if I fire the MY_ACTION action 100 times, The code will create a new object 100 times.

My question is what will happen to the previous state objects which are no longer in use. Will they be left to the javascript / browser garbage collector to decide what to do with ? If yes, isn't this a perfomance issue ie wont so many stale 'state' objects increase the load on the javascript garbage collector and thereby lower the performance of the code?

Redux itself is a simple state management library. Anything relating to garbage collection is handled by the Javascript engine. So no, the Redux creators did not "take this into account", because garbage collection has nothing to do with the Redux library itself.

Yes, immutable data handling does produce more objects than direct mutation, but JS engines handle that just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM