如何确定Node.js中的内存泄漏?有什么好的方法吗?

4

当部署我的node.js应用程序时,会出现内存相关错误(即FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory)。我想在本地对我的节点进行分析以查看是什么在占用内存,但不确定从哪里开始。


2
这个问题在这里得到了解答:https://dev59.com/2lTTa4cB1Zd3GeqPpBWy - Ryan Olds
那里的答案(使用来自节点检查器的分析器)让我们使用标记为“非常实验性”的东西,作者本人不推荐使用。 - Aaron Silverman
1个回答

2

您可以使用node-inspectorv8-profiler来完成此操作。从npm安装:

$ npm install v8-profiler

然后使用它来拍摄堆快照(从指令中拍摄):

var profiler = require('v8-profiler');
var snapshot = profiler.takeSnapshot([name])      //takes a heap snapshot

v8-profiler 目前对我来说无法使用:https://github.com/dannycoates/v8-profiler/issues/9 - Aaron Silverman
但是当它再次工作时,这可能是最好的方法,谢谢! - Aaron Silverman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接