I think you'll find that the problem is in one of the "..." sections you've omitted. Your foo1 code has been running on my machine all day without any issue at all.
-- Martin Cooper On Wed, Aug 21, 2013 at 8:22 PM, ming <[email protected]> wrote: > Hi, > My node.js program crashed and i saw the following in the log: > FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory > > i reduced the original program to the following tiny self-contained program: > > ============================= > ... > > function foo1() > { > var someBadURI = ...; > > http.get > ( > someBadURI, > function(res) > { > if (res.statusCode != 200) > { > util.log("!!!!! bad ...."); > setTimeout(foo1,0); > return; > } ... > } > ) ... > } > > foo1(); > ============================= > > If i let the program above run long enough (~30 minutes or more), the process > ran out of memory then crashed with the aforementioned error message but it > is not clear to me why: > FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory > > However, the following program has been running for days without any problem: > > ============================= > function foo2() > { > util.log("entering foo2"); > setTimeout(foo2,0); > util.log("leavinging foo2"); > } > > foo2(); > ============================= > > Why is that? Should the V8 engine register the event and invoke the > callback/handler constantly with 0-wait setTimeout? Why would it consume a > lot of memory? > > My guess is > * memory has been allocated for the http.get call in foo1. > In foo2, there is only log printing which does not really consume any > resource (memory in this case) > > * the call > setTimeout(foo,0); > in foo1 always grabs the next tick so the GC never gets a chance to run > > Am i way off? i'm unsure if i need to yank in scoped, handle, context, etc. > into my reasoning though for a better description. > > Thanks. > > -- > -- > 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.
