0

How to monitor memory leaks in windows (e.g. for tracking javascript leaks under IE)

>I’ve been trying to come up with a method that will show me the amount of memory consumed by IE over time, to check for memory leaks in the javascript code for a customer. Here is a small guide to how to do it with the programs available on Windows XP.

Note that trying cygwin and a *nix approach was my first thought. It doesn’t work. ‘ps’ in cygwin is not as capable as ‘ps’ found in *nix’es.

The tool to use is ‘perfmon’. You can find it in the menus as “Start -> Programs -> Administrative Tools -> Performance”. When you run it, follow these steps:

  • Go to system monitor in the left tab, and open the add dialog (using ‘+’ icon or Ctrl-I).
  • Run IE (or whatever program you want to monitor).
  • Choose  “Performance object: Process”, “Select counters from list”, in the counter list “Virtual Bytes”, “Select instances from list”, and the name of the IE process (or whatever process you want to monitor). We need this step, because IE might appear as multiple processes, e.g. IExplore, IExplore#1, etc., and we need to know which one is of interest for us. To find out whether you have found the correct process, add the “% processor time” counter as well, and observe that the process appear to be consuming processor time as you play with your IE window (or the process you want to monitor).
  • Now you know the name of your process, time to create a log for its counter. Expand “Performance Logs and Alerts” in the left tab, and choose “Counter Logs”.
  • Right click on the right pane, and select “new log settings”. Give a name to your log.
  • On the configure screen that appears, click “Add Counters”, and select “Performance object: Process”, “Select counters from list”, in the counter list “Virtual Bytes”, “Select instances from list”, and the name of the IE process (or whatever process you want to monitor). Click “Add”, and close the dialog.
  •  Set sample interval.
  • Go to “log files” pane. Here you may select whether you want to keep the log in binary (less space), or in csv (kind of human friendly). If you keep the log binary, you can convert it to csv later using a command line tool called ‘relog’, which is available in your Windows. (Note that while it isn’t listed in its parameter list, you should give relog the option ‘-o ‘ for it to output anything at all. See its help by running it with the parameter ‘/?’.)
  • Open your favorite spreadsheet (e.g. LibreOffice), open your csv, and convert it to a chart to your liking.

Short note on why you should use the counter “Virtual Memory”: this counts the total memory consumed by the program in its virtual memory space. You want this number, not the “Working Memory”, because if your program is leaking memory, and that memory is being paged out to the swap (or pagefile in MS jargon), that growth of pagefile usage is still a memory leak you should stop.

Hope this helps.
–eg

Leave a Reply

Your email address will not be published. Required fields are marked *