Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 i.e. wont so many stale 'state' objects increase the load on the javascript garbage collector and thereby lower the performance of the code?

like image 201
Nahush Farkande Avatar asked Mar 01 '17 06:03

Nahush Farkande


1 Answers

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.

like image 141
markerikson Avatar answered Oct 11 '22 00:10

markerikson