Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

In this tutorial, we’ll learn what the Garbage Collector Roots (GC roots) are. Additionally, we’ll describe the types of GC roots. Afterward, we’ll show the difference between GC roots and live objects.

2. GC Root Definition

Let’s first define what GC roots are. GC root is a term used in the context of garbage collection in Java. They are special objects for the garbage collector. As the name suggests, GC roots are starting points for the garbage collector processes. In general, all objects directly or indirectly referenced from a GC root are not garbage collected.

3. Types of GC Roots

Let’s have a look at the main types of GC Roots:

  • Class: Classes loaded by a system class loader; contains references to static variables as well
  • Stack Local: Local variables and parameters to methods stored on the local stack
  • Active Java Threads: All active Java threads
  • JNI References: Native code Java objects created for JNI calls; contains local variables, parameters to JNI methods, and global JNI references

Additionally, there are a few more possible types of GC Roots:

  • Objects used as monitors for synchronization
  • Specific objects defined by the JVM implementation that are not garbage collected for its purpose. That might contain important exception classes, system class loaders, or custom class loaders

Furthermore, there is no documentation per JVM about which specific objects are GC roots. Some of the popular Java IDEs provide the functionality to analyze memory from the GC roots perspective. This is beneficial when analyzing memory leaks in an application.

4. GC Roots vs. Live Objects

Let’s now have a look at the live objects defined in the garbage collection process.

All objects actively used by an application are live objects for GC. Furthermore, the garbage collector doesn’t delete live objects. GC roots are a special type of live object. Therefore, all GC roots are live objects by definition.

5. Garbage Collector Usage of GC Roots

Let’s now have a look at the usage of GC Roots in the garbage collection process.

As a matter of fact, all GC implementations in the HotSpot JVM are tracing collectors. GC identifies all live objects by traversing the objects graph. In addition, objects visited and marked as alive won’t be garbage collected. To be able to traverse the graph, starting points are necessary. Thus, GC roots are starting points for tracing collectors.

GC starts traversing the graph from the root and marks all visited objects in the graph as alive. The process executes for every GC root defined in an application. Moreover, it processes all graphs starting from all GC roots. Then, it marks all visited objects as alive. After that, all objects that haven’t been visited are garbage collected.

6. Conclusion

In this short article, we explained what GC roots are. Then, we described the types of GC roots. Next, we showed the difference between GC roots and live objects. Finally, we explained the usage of GC roots in the garbage collection process.

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW