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

It may be useful to launch the application with object allocation profiling right from the start using profiler agent startup options.

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 allows you to control overhead using the sampling interval parameter. For each .NET thread, the profiler maintains a counter that tracks the number of bytes allocated by that thread. When the counter exceeds the sampling interval during object creation, the profiler records an allocation sample.

Allocation profiling settings

The larger the sampling interval, the fewer samples are recorded and the lower the overhead. Conversely, the smaller the sampling interval, the higher the overhead. If the interval is set to 1, the profiler records allocation data for every object.

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 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 YourKit privacy policy.