© Iuliana Cosmina 2022
I. CosminaJava 17 for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-7080-6_13

13. Garbage Collection

Iuliana Cosmina1  
(1)
Edinburgh, UK
 

When executing Java code, objects are created, used, and discarded repeatedly from memory. The process through which unused Java objects are discarded is called memory management , but is most commonly known as garbage collection (GC) . Garbage collection was mentioned in Chapter 5, as it was needed for explaining the difference between primitive and reference types, but in this chapter we will go deep under the hood of the JVM to resolve yet another mystery of a running Java application.

When the Java garbage collector does its job properly, the memory is cleaned up before new objects ...

Get Java 17 for Absolute Beginners: Learn the Fundamentals of Java Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.