问题
We are implementing ngRedux for our Angular app. It all works nicely however I have on concern: memory usage, especially for mobile.
Our stores state object looks like this:
{
leads : [],
filters: [],
applictionStatuses: [],
}
Let's say on of our user selects a datefilter in the list of leads which will grab 30.000 leads from our API (a whole year for example).
As far as I understand redux, the state object will be cloned and then next object will look like
{
leads : [ {object}, {object} ...],
filters: [ dateRange: { start: {date}, end: {end} }],
applictionStatuses: [],
}
The leads object in the current state will hold 30.000 records. No when the user changes the date filter, it will update the state and create a new one with the new date filter. It will grab more or less records and at that into leads.
Theoretically the state object could look like:
{
leads : [ {object} ... times 40.000 ],
filters: [ dateRange: { start: {date}, end: {end} } ],
applictionStatuses: [],
}
Wouldn't this mean that at this time, in memory there would be 3 states stored with a total of 0 + 30.000 + 40.000 leads = 70.000 leads in memory. Any further change in state would duplicate the state and the leads on and on.
Only until I do a commit and squash the states, I would be occupying a lot of memory for lead records.
Is there a mistake in my reasoning or is this something that is inevitable with redux?
We could decide to take the Leads out of the redux store or put in a separate store so that there are not as many state objects with all those lead objects.
Very much interested in anyones opinion or consolidation.
Cheers
回答1:
No. Redux does not keep previous state trees in memory in production. See my comment at Is there any way to "commit" the state in Redux to free memory? for more info, as well as similar related answers at Can a Redux store lead to a memory leak? and Redux and ALL the application state .
来源:https://stackoverflow.com/questions/42686735/ngredux-state-with-big-data-collection-memory-concerns