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 Java application and add an extra load on the garbage collector. The Java machine 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 Java Profiler lets you manage allocation profiling using HTTP API endpoints:

Java API

The YourKit Java Profiler also provides a Java API for deep integration with Java applications. The com.yourkit.api.controller.v2.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:

Best practices

Choose the right profiling mode

Decide if you need full allocation stack traces (more detail but higher overhead) or if you only need object counting (less overhead, less detail). Start with simpler modes to pinpoint major allocation patterns and switch to more detailed modes only if necessary.

Limit profiling duration

Since object allocation profiling adds overhead to your Java 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.