4

I'm building an app in javascript and I would like to use console.log to preview everything that is on memory at runtime. I know I can check each variable selectively, but: is there a way to see everything?

Thankyou.

  • Have you tried **any** javascript console ? Chrome's console, Firebug for Firefox, IE's "F12 developer tools"... – Didier Ghys Dec 08 '11 at 15:54

2 Answers2

4

Install Firebug on Firefox. From there you can click on DOM and see all declared javascript variables. There's also an arrow on it that allows you to specify the source of the variables you would like to see such as "only user-defined properties" etc etc. Hope that helps you. (You could also console.log the window object as it contains everything)

.... EDIT .... After Josh's comments, I decided to take a look if any browser provided the power to actually look at the entire memory at a given time and Chrome's developer tools does exactly what your want. Simply start the developer tool - click 'Profiles' - then press the 'eye' icon in the bottom left and you'll get an entire collection of all things currently in memory (including items within closure). Hope this helps, your question has wound up helping me :)

Marlin
  • 751
  • 4
  • 8
  • Logging the global object (`window`) is a good idea, but it won't help you see variables in a closure. – josh3736 Dec 08 '11 at 16:14
  • Fair point. but its also part of the purpose of closure. To get around that without breaking any code that relies on it I suppose he could log the object from within EACH closure. But that could turn into an unruly amount of data :-/ – Marlin Dec 08 '11 at 18:24
1

For Google Chrome, there is Developer Tools, in which you can go to the Profiles tab to get a heap snapshot. The nightly Chromium builds seem to have a more detailed preview of memory usage than the current stable version of Google Chrome.

pimvdb
  • 151,816
  • 78
  • 307
  • 352