我正在运行一个带有 Node.JS 的 Socket.IO 服务器,它通常使用大约 400 MB 的内存,因为有大量数据被缓存以发送给客户端。然而,几个小时后,它在大约 40 分钟内突然开始增长到 1.4 GB 的使用量。有人告诉我使用 heapdump 来查找是否存在内存泄漏。
问题是 heapdump 结果只有 317 MB,里面没有任何异常,所以我一直在调试。我还使用 nodetime 运行它,它表示 V8 堆使用量约为 400 MB,但总的 V8 堆大小为 1.4 GB。
如何找出剩余 1 GB 的来源?
最佳答案
也许 node-memwatch 可以帮助您?
https://github.com/lloyd/node-memwatch
自述文件:
node-memwatch is here to help you detect and find memory leaks in Node.JS code. It provides:
A leak event, emitted when it appears your code is leaking memory.
A stats event, emitted occasionally, giving you data describing your heap usage and trends over time.
A HeapDiff class that lets you compare the state of your heap between two points in time, telling you what has been allocated, and what has been released.
关于Node.JS 进程使用 1.4 GB 内存,但 heapdump 只有 300 MB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22712220/