加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – Redux商店可以导致内存泄漏吗?

发布时间:2020-12-15 05:06:34 所属栏目:百科 来源:网络整理
导读:我有一个仪表板应用程序,其中有几个图表在设定的时间间隔内更新.我的第一个想法是更新商店中的数据,然后让所有图表从那里开始. 但这会导致内存泄漏吗?由于Redux每次数据更改时都会创建一个新存储,并保留旧存储.每秒~2mb的数据是否会堆积并使应用程序崩溃?
我有一个仪表板应用程序,其中有几个图表在设定的时间间隔内更新.我的第一个想法是更新商店中的数据,然后让所有图表从那里开始.

但这会导致内存泄漏吗?由于Redux每次数据更改时都会创建一个新存储,并保留旧存储.每秒~2mb的数据是否会堆积并使应用程序崩溃?

我看到的另一种方法是将数据保持在本地状态(使用setState).
我希望一些更有经验的React / Redux开发人员可以就此提出建议.谢谢!

Redux的创建者Dan Abramov解决了这个问题 here,如下所示:

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.

我认为这是答案的核心.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读