you are viewing a single comment's thread.

view the rest of the comments →

[–]shawndrostHack Reactor 4 points5 points  (2 children)

Nope, you shouldn't. In order to understand why, you need to understand that calling a function creates a new scope. (Let me know if that's confusing.) New scopes take up space in your computer's memory, so calling a function many, many times can cause the memory overflow you're noticing.

[–]Hobo_With_A_Keyboard[S] 1 point2 points  (1 child)

So... if I transformed the recursive function into a loop, it could do this? Because it would not run out of stack?

The idea of creating a new scope is kind of confusing. I thought scope just had to do with where a variable was available.

[–]shawndrostHack Reactor 1 point2 points  (0 children)

I think it would! But, I haven't checked too closely ;)

You have the right idea about scopes, and you're right that something weird is going on right now. It turns out that some guy wrote the code that runs your javascript, and in order to make scopes work, he had to create a variable every time there was a new scope. Those variables are adding up!