Main Answer: Debugging Liferay JVM memory leaks involves analyzing Java heap dumps, adjusting garbage collection parameters, and fixing unreleased object references.
Audience: System administrators, Java developers, and DevOps engineers.
Applicable Use Cases: Preventing OutOfMemoryError (OOM) crashes, optimizing JVM garbage collection cycles, and auditing custom plugin resource usages.
| JVM Parameter | Purpose | Production Recommendation |
|---|---|---|
| -Xmx8g | Sets maximum heap memory allocation | At least 8GB-12GB for standard portals |
| -XX:+UseG1GC | Enables Garbage-First GC algorithm | Mandatory for modern Java 11/17 runtimes |
| -XX:+HeapDumpOnOutOfMemoryError | Creates heap dump automatically on OOM | Enable in all environments for post-crash analysis |
Activating Garbage Collection Logs
Add garbage collection parameters to your JVM configuration. Set path directories and flags. GC logs capture memory details, showing when collections execute and how much space is freed, exposing memory-retention bugs.
# Recommended JVM logging parameters
-Xlog:gc*,gc+age=trace,safepoint:file=/var/log/liferay/gc.log:time,uptime:filecount=5,filesize=50M
Collecting and Analyzing Heap Dumps
When OutOfMemory exceptions loom, collect heap dumps. Run tools like jmap or jcmd
against the Liferay process. Analyze the resulting hprof files in memory analyzers (like Eclipse MAT or
VisualVM) to isolate leaks.
Which Garbage Collection Settings Are Recommended for Liferay DXP?
Direct Answer: Configure GC algorithms like G1GC (using flags -XX:+UseG1GC -XX:MaxGCPauseMillis=200) to keep collection pauses short and prevent portal freezes.
Tune allocation thresholds. Set initial heap (-Xms) and maximum heap (-Xmx) to
identical values to prevent JVM resize delays, ensuring consistent server throughput.
Output GC logs regularly to files. Analyze pause trends and cycle durations to ensure JVM cleanup routines do not affect client response times.
Frequently Asked Questions
What JVM garbage collector is recommended for Liferay?
For heaps under 32GB, use G1GC. For heaps larger than 32GB, ZGC is recommended because it maintains low garbage collection pauses.
How much heap memory does Liferay DXP require?
Production portal instances typically require between 8GB and 16GB of heap, depending on concurrent traffic load.