使用ngonchanges挂钩的内存泄漏
当使用ngonchanges
挂钩以访问对孩子组件中的输入属性的更改时,我正面临内存泄漏的问题。 我正在从父组件中发送大量数据(带有27000个项目的数组),并且数组中的数据以至少30Hz的频率更改。 我认为,垃圾收集器不会在更改中删除
对象的频率与上述频率相同。是否有一种手动方式可以从对象处置数据,或者有更有效的方法可以访问挂钩以外的输入属性上的更改?如果这不是内存泄漏的根本原因,请纠正我?如果需要,我可以共享我的代码。presotValue
的引用:SimpleChanges
I am facing an issue with a memory leak when using the ngOnChanges
hook to access the changes to an input property in my child component.
I am sending a large amount of data (an array with 27000 items) from my parent component and the data within the array is changing at a frequency of at least 30hz.
I think that the garbage collector is not removing the references of the previousValue
in the changes: SimpleChanges
object at the same frequency as mentioned above. Is there a manual way I can dispose of the data from the object or is there a more efficient way of accessing the changes on the input property other than the hook? Please correct me if that is not the root cause of the memory leak? I can share my code if required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
ngonchanges
正在导致内存泄漏,则无法从您的问题的细节中了解 - 如果这是Angular的最新版本,我会想象它不太可能是将其排除的一种方式,您可以使用
@Input
而不是ngonchanges
在使用上述方法时,请确保通过输入绑定IE在新数组中传递IE,IE设置器不会通过阵列突变
There is no way of knowing from the details of your question if
ngOnChanges
is causing a memory leak - if it's a recent version of Angular I would imagine it's pretty unlikelyAs a way of ruling it out, you could use property accessors with
@Input
instead ofngOnChanges
When using the above approach, make sure to pass in a new array via the input binding i.e. the setter won't be triggered via array mutations
在处理旧数据后
I was able to fix the issue by disposing of the old array references immeaditaley after I had processed the old data