简体   繁体   English

node.js 内存泄漏与集群和快递

[英]node.js memory leak with cluster and express

I am using the node.js 6.11.3 ,cluster module, express 4.14 Seeing memory leaks slowly over a period of 1 weeks.我正在使用 node.js 6.11.3 ,集群模块,表达 4.14 在 1 周内缓慢看到内存泄漏。 attached is a screenshot of the heap dumps in chrome dev tools.附件是 chrome 开发工具中堆转储的屏幕截图。 Cant tell the reason for the leak.无法说出泄漏的原因。 click for heap dump点击堆转储

Unfortunately, nobody can answer where your leak comes from without accessing the entire application and environment.不幸的是,没有人可以在不访问整个应用程序和环境的情况下回答泄漏的来源。 The real question is how do you debug a node memory leak.真正的问题是如何调试节点内存泄漏。

First its important to try to understand how memory leaks occur in Node.首先,尝试了解 Node.js 中内存泄漏是如何发生的很重要。 How is it possible if Node has built in garbage collection?如果 Node 内置了垃圾收集,那怎么可能呢? Well, variables are marked as garbage when no longer referenced.好吧,变量在不再被引用时被标记为垃圾。 If you have code (closures etc) that still hold reference to variables, they are not collected.如果您的代码(闭包等)仍保留对变量的引用,则不会收集它们。 That is just one example.那只是一个例子。 There are also dependencies that can cause memory leaks which can confuse you into thinking you have issues in your own code.还有一些依赖关系会导致内存泄漏,这会让您误以为自己的代码存在问题。 And maybe you do, in the way you use the dependency.也许你这样做了,就像你使用依赖的方式一样。

Bottom line, its best to get familiar with this debugging process yourself so that you can understand the issues leading to the leak.最重要的是,最好自己熟悉这个调试过程,以便您了解导致泄漏的问题。 Best of luck.祝你好运。 Here is one article that is helpful.这是一篇有用的文章。

https://www.alexkras.com/simple-guide-to-finding-a-javascript-memory-leak-in-node-js/ https://www.alexkras.com/simple-guide-to-finding-a-javascript-memory-leak-in-node-js/

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

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