Fully featured low overhead profiler for Java EE and Java SE platforms.
Easy-to-use performance and memory .NET profiler for Windows, Linux and macOS.
Secure and easy profiling in cloud, containers and clustered environments.
Performance monitoring and profiling of Jenkins, Bamboo, TeamCity, Gradle, Maven, Ant and JUnit.

Object allocation profiling

Creating objects (allocating memory in the heap) is an expensive operation. Therefore, creating a large number of temporary objects can significantly slow down a .NET application and add an extra load on the garbage collector. The .NET runtime will have to perform garbage collection more frequently, causing pauses in execution, which will ultimately negatively impact application performance.

Goals of object allocation profiling

  1. Identify parts of the code that generate the most temporary objects and put a strain on the garbage collector.
  2. Allocation profiling helps with fixing memory leaks. Additional information about where a specific object was created helps answer why it still exists in memory.

How to control object allocation profiling

You can start and stop object allocation profiling at any time while your application is running. When object allocations are not recorded, the profiler adds no overhead to the application.

Profiler UI

When the profiler is connected to an application, the toolbar shows these allocation profiling controls:

Toolbar button Description
Start allocation profiling Stop allocation profiling Start/Stop allocation profiling.
Clear profiling results Clear allocation profiling results and continue profiling.

Agent startup options

The following agent startup options control object allocation profiling. You can enable profiling from application startup, configure parameters for recording allocation data, and disable certain profiling capabilities to fine-tune profiler overhead:

HTTP API

If you need remote control or automation in your profiling workflow, YourKit .NET Profiler lets you manage allocation profiling using HTTP API endpoints:

.NET API

The YourKit .NET Profiler also provides a .NET API for deep integration with .NET applications. The YourKit.Profiler.Api.Controller includes methods for starting, stopping, and resetting the allocation profiling, similar to the toolbar buttons.

Allocations tab

The results of object allocation profiling can be analyzed from different perspectives:

Allocation profiling settings and overhead

Profiler overhead directly depends on the number of objects for which the profiler records a stack trace. The fewer stack traces the profiler records, the lower the overhead. YourKit .NET Profiler provides options that allow efficient allocation profiling while maintaining moderate performance overhead:

Allocation settings
  1. The first option specifies the minimum object size for which an allocation stack trace is always recorded. For example, if the minimum size is set to 4KiB, stack traces will be recorded for the creation of all objects of 4KiB or larger. This ensures that all significant allocations are captured.
  2. But what if the program creates many small objects? For this, there is a second option: "record every N-th object smaller than the minimum size". This option allows collecting statistical data on the creation of small objects.

As a result, with moderate performance impact, we can obtain complete information about all large object allocations and statistical data on small object allocations.

Best practices

Choose the right profiling options

Choose reasonable profiling settings to keep profiling overhead moderate. In most cases, it is not necessary to track the creation location of every object.

Limit profiling duration

Since object allocation profiling adds overhead to your .NET application, we recommend not keeping this mode enabled all the time. For example, if you want to profile object allocations when your web application processes an HTTP request, the optimal approach would be:

  1. Start allocation profiling just before executing the request.
  2. Execute the request, take a snapshot, and stop allocation profiling.
  3. Analyze the data in the snapshot.

With this approach, you can minimize performance impact and even profile in a production environment.

Validate changes

Always baseline performance before changes and re-measure after.

YourKit uses cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content, to analyze our website traffic, and to understand where our visitors are coming from.

By browsing our website, you consent to our use of cookies and other tracking technologies in accordance with the Privacy Policy.