- System requirements
- Profiler architecture
- Profiler installation
- Uninstall profiler
- Running the profiler
- Profiler activation
- Welcome screen
- Start profiling
- Profiling overhead
- Snapshots
- Solving performance problems
- CPU profiling
- Thread profiling
- Virtual threads support
- Object allocation profiling
- Memory profiling
- Monitor profiling
- Exception profiling
- Telemetry
- Probes: monitor events of various kinds
- Inspections: automatic recognition of typical problems
- Automatically trigger actions on event
- Automatic deobfuscation
- Summary
- Filters
- Profiler command line
- Export of profiling results to external formats
- Profiler Java API
- Profiler HTTP API
- Settings
- Troubleshooting and FAQ
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
- How to control object allocation profiling
- Allocations tab
- Best practices
Goals of object allocation profiling
- Identify parts of the code that generate the most temporary objects and put a strain on the garbage collector.
- 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/Stop allocation profiling. |
![]() |
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:
-
alloc_each
-
alloc_size_limit
-
alloc_heap_sampling
-
alloc_object_counting
-
disable_heap_sampling
-
disable_alloc
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:
- Telemetry charts.
- Class - Allocated objects grouped by their class.
- Allocation tree - All threads merged - Displays methods that allocated objects, organized into a single combined call tree across all threads.
- Allocation tree - By thread - Displays methods that allocated objects, organized into separate call trees per Java thread.
- Flame graph - Displays methods that allocated objects as a flame graph.
- Hot spots by object count - Methods allocating the highest number of objects.
- Hot spots by object size - Methods allocating the most memory.
- Method list - Provides a complete list of all methods responsible for object allocations.
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:
- Start allocation profiling just before executing the request.
- Execute the request, take a snapshot, and stop allocation profiling.
- 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.