- 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
Memory profiling
Memory profiling is an essential aspect of performance optimization for any Java application. It involves monitoring and analyzing the runtime behavior of your application in terms of memory usage, object creation, and garbage collection.
- Goals of memory profiling
- Common problems and solutions
- How to start memory profiling
- Best practices
Goals of memory profiling
1. Identify memory leaks: Detect areas in the code where objects are being created but not released, leading to increased memory usage over time.
2. Optimize memory usage: Identify and improve areas where unnecessary memory is allocated or where more efficient data structures can be used.
3. Garbage collection analysis: Understanding how garbage collection (GC) impacts your application can help in tuning it for better performance.
4. Improve application speed: Efficient memory use generally leads to faster execution as fewer CPU cycles are wasted in allocation and deallocation.
5. Enhance scalability: Reducing the memory footprint of an application can make it more scalable, allowing it to handle more users or larger data sets.
Common problems and solutions
Memory leaks
Analyze memory snapshot to find the leaking objects. Identifying key memory consumers by analyzing dominators. Group objects by different categories to evaluate how much memory they use.
High memory usage
Find which data structures or objects consume the most memory. Consider using more memory-efficient data structures or algorithms.
Frequent garbage collection
GC telemetry charts can show how often garbage collection is occurring. Profile object allocations to learn where in the code each object was allocated, and find the objects that are being created and discarded rapidly. Use object pooling or revise the code to minimize object creation. You can tune JVM flags for garbage collection strategies or increase the heap size.
OutOfMemoryError
Capture HPROF snapshot right when your Java
application crashes due to an OutOfMemoryError
, and find the root cause.
Increase the heap size using -Xmx
flag.
How to start memory profiling
When the profiler is connected to an application, the toolbar shows these memory profiling controls:
Toolbar button | Description |
![]() |
Capture memory snapshot - save the profiling results to a file for comprehensive analysis. |
![]() ![]() |
Start/stop object allocation profiling. |
![]() |
Clear recorded object allocations and continue profiling. |
![]() |
Explicitly run garbage collector in the profiled application. |
Best practices
1. Focus on key memory consumers: Rather than attempting to optimize all parts of your application at once, focus your efforts on the components or data structures that consume the most memory. These are often the areas where optimizations will have the most impact.
2. Detect anomalies: Keep an eye out for any irregular patterns or anomalies in your memory profiling data. Sudden spikes in memory usage or unexpected object retention could signal a problem that needs immediate attention.
3. Regular profiling: Make memory profiling a regular part of your development cycle.
4. Start small: Don't wait for issues to manifest in production; start memory profiling with development or staging setups.