简体   繁体   中英

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 .

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.

Is there something I should do to tell node.js not to keep old domains ?

From the docs:

domain.exit()

The exit method exits the current domain, popping it off the domain stack. 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.

If there are multiple, nested domains bound to the current execution context, exit will exit any domains nested within this domain.

Calling exit changes only the active domain, and does not alter the domain itself. Enter and exit can be called an arbitrary number of times on a single domain.

If the domain on which exit is called has been disposed, exit will return without exiting the domain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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