Using NetBeans to profile garbage collection with GC logs
Garbage collection affects responsiveness, throughput and memory costs in every Java application. NetBeans IDE gives developers a practical place to launch a program with diagnostic JVM options, inspect heap behaviour and correlate pauses with application activity.
GC logs add the detail that a live profiler may miss. They show when collections occur, which collector is active, how much memory is reclaimed and how long the JVM stops application threads. With a consistent workflow, developers in Sydney, Melbourne, Brisbane or Perth can investigate performance issues before they reach production.
Prepare NetBeans and the Java runtime
Start with a representative project and a reproducible workload. In NetBeans, open the project properties and locate the run configuration where JVM arguments can be supplied. The exact menu wording can vary between NetBeans releases, Java versions and project types, so confirm that the options are being passed to the application rather than to the IDE itself.
For modern Java releases, a useful baseline is:
-Xlog:gc*,safepoint:file=logs/gc-%t.log:time,uptime,level,tags:filecount=5,filesize=20M
This unified logging syntax works with Java 9 and later. Java 8 applications generally use options such as -XX:+PrintGCDetails, -XX:+PrintGCDateStamps and -Xloggc:logs/gc.log. Avoid copying Java 8 flags into a current JDK without checking compatibility, because unsupported options can prevent the program from starting.
Create the logs directory before running the application, or use a path that the process can write to. Rotating files are safer than a single unlimited log, especially when testing locally on a laptop connected through a busy home NBN service.
Capture useful evidence during a run
A GC log is most valuable when it represents a known scenario. Record the JDK version, heap settings, collector, test duration and workload. A NetBeans project that processes a fixed batch or handles a repeatable HTTP test makes comparisons much easier than an interactive session with changing inputs.
NetBeans Profiler can provide complementary telemetry: heap usage, thread activity, CPU samples and garbage collection events. Start a profiling session, exercise the slow operation, and note the time at which latency rises. Then match that interval with the GC log. A spike in allocation rate, repeated young collections or a long old-generation pause can explain an otherwise vague CPU or response-time warning.
Keep timestamps understandable. Unified logs can include elapsed JVM time, while application logs may use local time. Teams working across AEST, AEDT and AWST should record the timezone used by the test harness. This is especially helpful when a Melbourne developer compares results with a service running in an AWS Sydney region.
Read the main GC log signals
Look first at collection frequency and pause duration. Frequent short young-generation collections often indicate heavy object allocation rather than a leak. Longer old-generation or mixed collections can point to a heap that is too small, objects that remain reachable for too long, or an unsuitable collector configuration.
A simplified log line may contain a pattern like:
[12.345s][info][gc] GC(18) Pause Young ... 512M->146M(1024M) 42.1ms
The first values show used memory before and after collection, followed by the committed heap size. The final duration is the pause observed by application threads. A single 42-millisecond event may be harmless for a batch job but significant for an interactive trading, booking or retail system with a strict response-time target.
Look for promotion pressure, allocation stalls, humongous objects and full collections. A heap that repeatedly rises close to its maximum after each cycle deserves investigation. It may indicate retained references, large caches, oversized buffers or a workload that genuinely needs more memory. Increasing -Xmx can postpone the symptom while creating longer pauses and higher cloud costs.
Compare results inside a controlled workflow
The NetBeans editor is useful for opening rotated GC log files and searching for terms such as Pause, Full, Humongous, to-space exhausted or allocation failure. For larger files, external log visualisers can calculate pause percentiles and allocation rates. Keep the raw files alongside the test result so a later review can verify any chart or summary.
| Signal | Likely meaning | NetBeans follow-up |
|---|---|---|
| Many short young pauses | High allocation rate | Use CPU and heap telemetry to find allocation-heavy code |
| Long mixed or old pauses | Tenured objects or limited heap headroom | Inspect retained objects and compare heap sizing |
| Full GC events | Severe memory pressure or promotion failure | Check leaks, explicit GC calls and collector settings |
| Heap remains high after GC | Live objects are retained | Use a heap dump and inspect reference paths |
| Large pause variance | Bursty workload or contention | Repeat the same scenario and compare percentiles |
Change one variable at a time. Run the same test with identical input, then alter the heap size, collector or application code. Do not compare a 10-minute Melbourne test on one JDK with a 30-minute Brisbane test on another and treat the difference as a tuning result. Version, hardware, container limits and background services all affect GC behaviour.
For broader NetBeans and Java development material, the NetBeans developer blog can provide useful context about IDE configuration and Java tooling. The key is to treat GC tuning as an evidence-based experiment, not a collection of universal flag recommendations.
Apply findings safely in Australian deployments
A developer workstation is only a model of production. Container memory limits, CPU quotas and cloud instance types change the JVM's view of available resources. Before applying a setting to a customer-facing service, test it in an environment that resembles the target deployment, including its Australian region, traffic shape and monitoring configuration.
GC logs can grow quickly and may contain class names, file paths, request identifiers or other operational details included by surrounding logging. Apply sensible retention and access controls under the organisation's security policy. For systems handling customer information, review whether logs could expose data relevant to Australian Privacy Principles obligations.
Use the following checks when profiling and tuning:
- Enable rotating GC logs with a clear retention period and writable path.
- Record JDK, collector, heap limits, CPU allocation and test workload.
- Correlate pause timestamps with NetBeans profiler data and application latency.
- Investigate retained objects with a heap dump before simply increasing
-Xmx. - Compare pause percentiles across repeated runs rather than relying on one event.
- Recheck settings during Australian peak periods, such as end-of-financial-year processing or major retail campaigns.
Teams can also keep IDE configuration references close to their wider development documentation. A guide to Node.js setup is useful when a Java service is developed alongside a JavaScript frontend, while Australian technology resources may help place local hosting and engineering decisions in a broader market context. The GC evidence itself should remain specific: identify the collector, explain the pause pattern and connect every tuning change to a measured application outcome.