dotMemory 2024.2 Help

Analyze Memory Allocation

Use the Memory Allocation view to analyze allocations on a specific time interval: find out what objects were allocated on this interval and what functions allocated these objects. The view can show you allocation data even when profiling is still in progress: memory snapshots aren't required.

Data collection modes

dotMemory can collect memory allocation data in one of two modes:

Sampled

(Default, Windows only) dotMemory collects limited allocation data: For each function that allocates objects, you can view only approximate object sizes. The information about object count is not available.

The pros of the Sampled mode:

  • It doesn't slow down the profiled application.

  • You can use it when the profiler is attached to an already running application.

The data is not detailed because it is based on ETW events: the allocation event is triggered each time the size of the allocated memory exceeds 100KB in total. For example, a thread allocates five 50 KB memory blocks during profiling. In such a case, dotMemory will detect only two allocations of 100 KB.

Memory allocation
Full

dotMemory collects detailed allocation data: It includes the exact size of allocated objects and object count.

The cons of the Full mode:

  • It significantly slows down the profiled application.

  • You cannot use it when the profiler is attached to an already running application.

You can switch between these modes anytime during the profiling session. Note that if you want to analyze full allocation data, the Full data collection mode must be enabled during the desired time range. If this range contains intervals with Sampled data, the Memory Allocation view will show you only sampled allocation data.

Data collection mode

How to get memory allocation data

To analyze memory allocation on an arbitrary time interval

Analyzing traffic
  1. Start a profiling session or open an existing workspace (created in dotMemory 2021.1 or later).

  2. Depending on how detailed data you want to get, use either Sampled or Full data collection mode.

  3. On the Timeline graph, select a desired time interval.

  4. Click the Allocated: ... MB link or the Show memory allocation button to open the Memory Allocation view.

    Open time interval
  5. Choose how you want to analyze the data: using grouping by Types, by Methods, by Call Tree, or by Subsystems.

To analyze memory allocation between the start of the session and a specific snapshot

Analyzing traffic
  1. Start a profiling session or open an existing workspace.

  2. Under Memory Snapshots, find the required snapshot and click Memory allocation.

    View Memory Allocation Snapshot
  3. Choose how you want to analyze the data: using grouping by Types, by Methods, Call Tree, or by Subsystems.

To analyze memory allocation between two snapshots

Analyzing traffic
  1. Start a profiling session or open an existing workspace.

  2. Under Memory Snapshots, find the required snapshots and add them to the Snapshot Comparison area by clicking Add to comparison for each snapshot.

  3. In Snapshot Comparison, click View memory allocation.

    View Memory Allocation Two Snapshots
  4. Choose how you want to analyze the data: using grouping by Types, by Methods, by Call Tree, or by Subsystems.

Types

Memory Allocation view

The Types view consists of two parts: the object list and the Back Traces tree.

Objects list

The list shows you the objects allocated on the selected time interval grouped by the object type. Select a particular type to see what functions allocated the objects of this type.

Name

Description

Type

Type name.

Objects

The number of objects of the same type.

Bytes

The overall shallow size of the objects in bytes.

Back Traces

The Back Traces tree shows you all call trees that have allocated the objects currently selected in the object list. The calls are shown from the bottom up: the last call in the call stack is the top node. In other words, Back Traces is the inverted call tree.

You can sort the tree by the amount of allocated memory (Total / Own Bytes) or by the number of allocated objects (Total / Own Objects). To switch the sorting, click the Total / Own ... column header.

The Total / Own ... column shows how much memory (objects) were allocated in a particular call tree (Total) or in a particular call (Own).

For example:

Back Traces

The set_Capacity method allocated 149.80 MB (Own). The method was called from two call stacks:

  • through the AddWithResize method: 142.69 MB

  • and through the EnsureCapacity method: 7.11 MB

To view where in the Call Tree a particular method is called, right-click the method and choose Show occurrences of this method in 'Call Tree'. This will show the call tree containing all method calls merged.

Methods

Memory allocation by methods

The Methods view consists of three parts: the method list, the Back Traces tree, and the sunburst diagram of the top five allocated object types.

Methods list

The list shows you the methods called during the selected time interval. Select a particular method to see what object types were allocated by the method as well as the method's back traces tree. Note that each method in the list is unique – it represents all calls of this method from all call stacks.

Name

Description

Method

Method name.

Objects

The number of objects allocated by method calls.

Bytes

The overall shallow size of the objects in bytes.

Back Traces

The Back Traces tree shows you all call stacks that called the method currently selected in the method list. The calls are shown from the bottom up: the last call in the call stack is the top node. In other words, Back Traces is the inverted call tree.

The Back Traces tree is similar to the one in the Types view.

Call Tree

Memory allocation by call tree

The Call Tree view shows the call tree for the selected time interval. If a call allocated objects, the object types will be shown in the tree below the call.

The Total / Own ... column shows how much memory (objects) were allocated in a particular call tree (Total) or in a particular call (Own).

You can sort the tree by the amount of allocated memory (Total / Own Bytes) or by the number of allocated objects (Total / Own Objects). To switch the sorting, click the Total / Own ... column header.

To filter the call tree, start typing in the Filter field. Learn more about how to set filters

To view a subsystem for a particular method, right-click the method and choose Show this method's subsystem.

Subsystems

Subsystems

A subsystem groups all methods belonging to a particular type, namespace, or assembly. To switch the grouping type, use the Type, Namespace, and Assembly buttons at the top of the table. Use the Subsystems view to quickly understand how much memory a particular application component allocates. For example, this view is especially helpful for evaluating memory allocation of your newly added or refactored code.

Each subsystem includes all objects created by its entire call subtree (Total size). For example, in a console application, the subsystem of the type Program will include all objects created by the application as Program.Main() is the top node in the app's call tree.

Subsystems is a master-detail view. Choose a subsystem in the table on the left, and on the right you will see:

  • Top five types that were allocated by instances of the selected subsystem.

  • Top five methods of the selected subsystem that allocated most of the memory.

  • Merged call tree for the selected subsystem.

    If a call allocated objects, the object types will be shown in the tree below the call.

    The Total / Own ... column shows how much memory (objects) were allocated in a particular call tree (Total) or in a particular call (Own).

    You can sort the tree by the amount of allocated memory (Total / Own Bytes) or by the number of allocated objects (Total / Own Objects). To switch the sorting, click the Total / Own ... column header.

    To view the location of a particular method in the application call tree, right-click the method and choose Show this method in 'Call Tree'.

Exclude subsystems from scope

An application contains many subsystems of no interest for further analysis. For example, it is clear that a subsystem for the System.Windows.Application type will include all calls made during the profiling session as the application is started by the Application.Run() method. In such cases, you can exclude the subsystems that you don't want to analyze.

To exclude a subsystem from analysis

  1. Select a subsystem in the list.

  2. Press Del or right-click the subsystem and choose Exclude from scope in the context menu.

  3. dotMemory will gray out the excluded subsystem and put it to the end of the subsystem list.

To return the excluded subsystem back

  1. Scroll to the end of the subsystem list.

  2. Select the excluded subsystem.

  3. Press Del or right-click the subsystem and choose Return back to scope in the context menu.

Last modified: 24 July 2024