简体   繁体   English

node.js域内存泄漏

[英]node.js domain memory leak

I attach a new domain to each incoming request in my Express app, just like in the example in the node.js doc . 我将新域附加到Express应用程序中的每个传入请求中,就像node.js doc中的示例一样。

However, I noticed I was leaking memory. 但是,我注意到我正在泄漏内存。 When I do a heapdump and inspect it in Chrome, I notice that classes that should be garbaged immediately are actually retained by old domains. 当我进行堆转储并在Chrome中对其进行检查时,我注意到应该立即进行垃圾处理的类实际上是由旧域保留的。

Is there something I should do to tell node.js not to keep old domains ? 我应该做些什么来告诉node.js不要保留旧的域吗?

From the docs: 从文档:

domain.exit() domain.exit()

The exit method exits the current domain, popping it off the domain stack. exit方法退出当前域,将其从域堆栈中弹出。 Any time execution is going to switch to the context of a different chain of asynchronous calls, it's important to ensure that the current domain is exited. 每当执行将要切换到不同的异步调用链的上下文时,确保退出当前域就很重要。 The call to exit delimits either the end of or an interruption to the chain of asynchronous calls and I/O operations bound to a domain. 退出调用界定了绑定到域的异步调用和I / O操作链的结束或中断。

If there are multiple, nested domains bound to the current execution context, exit will exit any domains nested within this domain. 如果有多个嵌套域绑定到当前执行上下文,则exit将退出该域内嵌套的所有域。

Calling exit changes only the active domain, and does not alter the domain itself. 调用exit只会更改活动域,而不会更改域本身。 Enter and exit can be called an arbitrary number of times on a single domain. 可以在单个域上多次调用Enter和Exit。

If the domain on which exit is called has been disposed, exit will return without exiting the domain. 如果已放置调用出口的域,则退出将返回而不退出该域。

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

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