Let me take a stab at rephrasing these bits in easier to understand terms: On Fri, Jan 10, 2014 at 7:26 AM, Tamil selvan R.S <[email protected]>wrote:
> *In order to prevent excessive memory usage, Domain objects themselves are > not implicitly added as children of the active domain. If they were, then > it would be too easy to prevent request and response objects from being > properly garbage collected* > This is saying that there's no parent-child relationship between domains, so if you create one domain while another one is active, the two will not be connected to each other. This is because if the domain system automatically managed those relationships, you might end up with a lot of domains with references to other domains, and none of them would ever get garbage collected until all of them were no longer used. Because the request and response objects used by HTTP conversations are EventEmitters, they're automatically bound to domains, so they too would end up getting retained for too long. This would look and feel like a memory leak. As an aside, something I've learned that's confusing for people new to working with domains is figuring out which parts are done automatically, and which you're responsible for managing yourself. For example, if you create a new EventEmitter, socket, or stream within an active domain, Node takes care of binding that object to the domain, but if you want to add an existing object (and its bound handlers) to the domain, you're responsible for using something like domain.add to do the binding yourself. Written down, it's easy to see the difference between the two, but in practice it takes some experience to get comfortable with how domain binding works. The documentation could stand to be clearer around this, but coming up with simple, clear language to describe this stuff is hard. > Implicit binding routes thrown errors and 'error' events to the Domain's > error event, but* does not register the EventEmitter on the Domain, so > domain.dispose() will not shut down the EventEmitter. Implicit binding only > takes care of thrown errors and 'error' events* > The best advice I can give here is never, ever use domain.dispose. It was an interesting idea that didn't work out, and it's deprecated in Node 0.12. See http://blog.izs.me/page/6 for a more in-depth explanation as to why. Hope this helps! Forrest Can Someone Help me understand the above two points with some scenario or > code? I'm getting lost how many ever times I read the doc. > > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
