Collecting .NET Memory Allocation and Lifetime Data

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Collecting .NET Memory Allocation and Lifetime Data.

INCLUDEvsprvs] Profiling Tools support the collection of .NET memory allocation and object lifetime data, which helps you detect memory-related performance issues in your application.

  • Data about .NET memory allocation includes the size and number of .NET Framework memory objects that were allocated.

  • Object lifetime data includes the size and number of .NET Framework memory objects that were reclaimed in the three garbage collection generations.

Requirements

  • Visual Studio Ultimate, Visual Studio Premium, Visual Studio Professional
System_CAPS_ICON_note.jpg Note

Enhanced security features in Windows 8 and Windows Server 2012 required significant changes in the way the Visual Studio profiler collects data on these platforms. Windows Store apps also require new collection techniques. See Performance Tools on Windows 8 and Windows Server 2012 applications.

You can collect data by using either the sampling or the instrumentation profiling method.

  • When you use the sampling method, the profiler tracks all .NET memory allocations and objects that are generated by the process that was started or attached to.

  • When you use the instrumentation method, the profiler tracks only those .NET memory allocations and objects that are generated by the instrumented modules.

System_CAPS_ICON_important.jpg Important

When you are collecting .NET memory data (allocations, object lifetimes, or both) by using the sampling method, all user-specified sampling events are ignored, and the appropriate memory allocation events are used to collect data.

If you enable the profiling of.NET memory allocation, you also enable the Allocation View. If you enable the profiling of .NET lifetime data, you also enable the Objects Lifetime View. For more information, see Allocations View and Object Lifetime View.

For information about how to collect .NET memory data by using the Profiling Tools command-line tools, see Using .NET Memory Methods to Collect Memory Allocation and Object Lifetime Data in Using Profiling Methods From the Command Line.

To collect .NET memory data

  1. In Performance Explorer, right-click the performance session, and then click Properties.

  2. On the Performance SessionProperty Pages dialog box, click the General tab, and select the Collect .NET object allocation information check box.

  3. To collect .NET object lifetime data, select the Also collect .NET object lifetime information check box.

You can specify additional options in the Performance SessionProperty Pages dialog box of the performance session. To open this dialog box:

  • In Performance Explorer, right-click the performance session name, and then click Properties.

The tasks in the following table describe options that you can specify in the Performance SessionProperty Pages dialog box when you collect .NET memory data.

TaskRelated Content
On the General page, specify naming details for the generated profiling data (.vsp) file.- Collecting .NET Memory Allocation and Lifetime Data
- How to: Set Performance Data File Name Options
On the Launch page, choose the application to start if you have multiple .exe projects in your code solution.- Collecting tier interaction data
On the Tier Interaction page, add ADO.NET call data to the profiling run.- Collecting tier interaction data
On the Windows Events page, specify one or more Event Tracing for Windows (ETW) events to collect with the sampling data.- How to: Collect Event Tracing for Windows (ETW) Data
On the Windows Counters page, specify one or more operating system performance counters to add to the profiling data as marks.- How to: Collect Windows Counter Data
On the Advanced page, specify the version of the .NET Framework runtime to profile if your application modules use multiple versions. By default, the first version loaded is profiled.- How to: Specify the .NET Framework Runtime

The tasks in the following table are options in the Property Pages dialog box that are specific to profiling with the instrumentation method.

TaskRelated Content
On the Binaries page, specify a location for the instrumented copies of the modules. By default, the original binaries are moved to a backup folder.- How to: Relocate Instrumented Binaries
On the Instrumentation page, exclude small functions from profiling to reduce the profiling overhead, profile JavaScript code in ASP.NET Web pages, and specify commands to run at a command prompt before and after the instrumentation process.- How to: Exclude or Include Short Functions from Instrumentation
- How to: Profile JavaScript Code in Web Pages
- How to: Specify Pre- and Post-Instrument Commands
On the CPU Counters page, specify one or more processor performance counters to add to the profiling data.- How to: Collect CPU Counter Data
On the Advanced page, specify any additional VSInstr.exe options that you want, such as options to include or exclude specific functions. For more information about VSInstr options, see VSInstr- How to: Specify Additional Instrumentation Options
- How to: Limit Instrumentation to Specific Functions

Configuring Performance Sessions
How to: Choose Collection Methods
Performance Session Properties

Show: