简体   繁体   English

React 组件卸载后如何检查对象、订阅、网络请求等待清理?

[英]How do I check objects, subscriptions, network requests pending cleanup after React component unmount?

Is there a way to see unnecessary objects still in memory or pending network requests after the React component has unmounted?有没有办法在 React 组件卸载后查看仍在 memory 中的不必要对象或待处理的网络请求? If I can see that then I can handle that in componentWillUnmount().如果我能看到,那么我可以在 componentWillUnmount() 中处理它。

Amir Saleem already mentioned Axios for handling requests. Amir Saleem 已经提到Axios用于处理请求。 I don't think, that you need to be very concerned about garbage collection in JavaScript as the language interpreter does that for you.我不认为,您需要非常关注 JavaScript 中的垃圾收集,因为语言解释器会为您执行此操作。

That is a huge difference to C/C++ or some other low level languages where you are responsible for creating and deleting unused memory space.这与您负责创建和删除未使用的 memory 空间的 C/C++ 或其他一些低级语言有很大的不同。

Just put in the time to use good, tested and efficient algorithms in your code and let the Garbage Collector do the rest.只需花时间在代码中使用良好、经过测试和高效的算法,让垃圾收集器执行 rest。 Your whole component will be garbage collected if you're no longer using it.如果您不再使用它,您的整个组件将被垃圾收集。

If you really want an overview of the objects in your application, Firefox has a Memory feature in the developer console.如果您真的想了解应用程序中的对象,Firefox 在开发人员控制台中有一个 Memory 功能。 It looks like that:它看起来像这样:

在此处输入图像描述

See more information on Memory Management .请参阅有关Memory 管理的更多信息。 Avoiding Memory Leaks in NodeJS might also be interesting for you. 避免 NodeJS 中的 Memory 泄漏对您来说可能也很有趣。 Please see also the references on the bottom of the last page.另请参阅最后一页底部的参考资料。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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