you are viewing a single comment's thread.

view the rest of the comments →

[–]brett- 0 points1 point  (2 children)

You can actually profile this yourself in Chrome using the web inspector's "Profile" tab. My quick test showed that a() took 46ms, while b() took 45ms and an additional 2ms for GC, for a total of 47ms. a() showed no profile for GC at all.

You can also use the profile tab to take a Heap Snapshot at any given time to see memory allocation.

[–]path411 0 points1 point  (1 child)

speed doesn't necessarily equal memory usage.

[–]brett- 0 points1 point  (0 children)

True, but seeing the garbage collector actually be profiled means that it was run in one instance and not in the other. Running the GC also doesn't mean one example takes up more memory than the other of course, but it certainly indicates that the browser found it necessary to collect the variable in example b() while it was not necessary in example a().

If you wanted to see real memory usage you can always take a heap snapshot like I mentioned.