Hacker News new | ask | show | jobs
by glasser 4735 days ago
I don't know how to look at memory usage in other modern JS interpreters like those used in FireFox and Safari. Anyone able to check to see if they have this problem? (And if they manage to avoid the memory leaks in the first two code samples?)
2 comments

In Firefox you could always do it manually with about:memory -- 1MB a second should be easy enough to notice. Not sure they've added a way to get a pretty graph yet, though. Probably Firebug has a way?

I wonder if using the "use strict" directive would let the browser optimize this more easily? Probably not, but Javascript does have a lot of crazy corner cases, and one of them might be preventing (or just making it harder to prove safe) the optimization.

e: Here's an example of one of those corner cases:

    console.log = eval
Now whether those functions reference a particular variable depends on the string they're printing! And this swap out of log() could be done at any time.

e2: Ah, as glasser and pcwalton point out, an indirect reference to eval doesn't work the same way as a direct call. TIL!

No, actually, you literally have to call eval as a function called eval if you want to get the local lexicals. See sections 10.4.2 and 15.1.2.1.1 of the ECMAScript standard, or try it out:

   > (function () { var x = 5; eval("console.log(x)"); })()
   5
   > (function () { var x = 5; var e = eval; e("console.log(x)"); })()
   ReferenceError: x is not defined
I haven't checked the first two samples but:

* Safari 5.1 exhibits no significant heap growth, as far as the timeline shows anyway

* Using top to observe private memory, Firefox does seem experience significant heap growth on the provided program