Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News JavaScript Memory Analyzer in Visual Studio 2012 Identifies Leaks in Windows Store Apps

JavaScript Memory Analyzer in Visual Studio 2012 Identifies Leaks in Windows Store Apps

This item in japanese

Visual Studio 2012 Update 1 includes a JavaScript memory analysis tool for Windows 8 that enables developers to identify how much memory is being consumed by a JavaScript based Windows Store app and is available for Visual Studio 2012 Express, Professional, Premium and Ultimate on Windows 8.

The Launch startup project option in JavaScript memory tool enables developers to analyze the startup project in the current Visual Studio instance. The Launch installed App Package option launches the Windows Store app which enables Visual Studio 2012 to start the diagnostic session. The last option, Attach to running app prompts you to attach to the already running apps to enable Visual Studio to start the diagnostic session.

A process memory graph will be displayed when you launch the JavaScript memory tool that allows you to observe the amount of memory consumed by the app over time. The graph gives you an indication of the memory trend for the app which enables you to judge when it is appropriate to take a heap snapshot.

In order to inspect JavaScript memory, you have to make use of Take a Snapshot option, which generates a summary tile that indicates the size of the JavaScript heap at the time the snapshot was taken along with the number of objects allocated in addition to a screenshot of the application.

You can continue to capture snapshots at regular intervals and you can use the generated additional tiles for future comparison. Moreover, built-ins and objects IDs can be shown in the details table by using the drop down at the top right corner of the details view.

It is also possible to capture snapshots programmatically using console.takeHeapSnapshot, which takes a snapshot that appears on the tool and console.profileMark, which displays a profile mark in the memory graph while the diagnostic session is running including the ability to annotate the graph with custom marks.

Sometimes, you will be required to check for existence of the commands before usage, since they are only available in the context of the memory analyzer:

if (console && console.takeHeapSnapshot)

By default, the snapshots collection is saved to disk under a diagnostic sessions folder, which contains .diagsession files. It can then be renamed, shared across teams and can also be reopened in compatible versions of Visual Studio 2012. The snapshot tiles and the details views can be inspected upon opening the file.

Image Source - MSDN & Dr. Dobbs

Rate this Article