In Java, the allocation and recycling of object memory space is done automatically by the garbage collection process in the JVM. Unlike the C language, developers do not need to write code specifically for garbage collection in Java. This is one of the many features that have made Java popular and has helped programmers write better Java applications.
This is a four-part series of tutorials to understand the basics of garbage collection in Java,
- Introduction to Java Garbage collection
- How does Java garbage collection work?
- Types of Java garbage collector
- Monitor and analyze Java garbage collection
This tutorial is the first part of the series. This article explains some of the basic terminology, like the Jdk,jvm,jre,hotspot VM, and then understands the architecture of the JVM and the Java heap memory structure. Before entering the garbage collection tutorial, it is important to understand what these basics are.
Key Java noun terminology
- Java API – is a collection of well-packaged libraries that can help developers create Java applications
- Java Development Kit (JDK) – is a toolset that enables developers to create Java applications. The JDK includes tools for compiling, running, packaging, publishing, and monitoring Java applications.
- Java Virtual Machine (JVM) JVM does is an abstract computer device. Java programs are written according to the JVM specification. The JVM is for a specific platform, which translates Java programs into the underlying platform-specific instructions to execute. The JVM makes the Java program platform-Independent.
- Java Runtime Environment (JRE) –JRE consists of JVM implementations and Java APIs.
Java HotSpot Virtual Machine
Each JVM implementation may differ in the way that the garbage collection principle is implemented. Prior to the acquisition of Sun, Oracle had already jrockit the JVM and, after acquiring it, had a hotspot JVM. Oracle now maintains two JVM implementations at the same time, and Oracle has declared that the two JVM implementations will be consolidated into one after a period of time.
The HotSpot JVM is a core component of the Oracle SE platform segment. In this garbage collection tutorial, we will see the garbage collection principle based on the hotspot virtual machine.
JVM Architecture
Outlines the key components in a JVM. In the JVM architecture, the two main components associated with garbage collection are heap memory and garbage collector. The heap memory is the runtime data region, and the instance is present, and the garbage collector operates in that area.
Now we know how these things fit into bigger plans.
Java Heap Memory Heap memories
It is important to understand the role of heap memory in the JVM memory model. The Java instance is stored in the heap memory area at run time. When an object is no longer referenced, it has the opportunity to remove it from the heap memory. In the garbage collection process, those objects are removed from the heap memory and the space is reclaimed. Heap memory has three zones,
- Young Generation Generation
- Eden Zone (any instance enters the run-time memory area)
- S0 survivor Area (a longer instance from Eden Zone to S0)
- S1 survivor Zone (a longer instance from the S0 zone to S1)
- Old generation (instance promoted from S1)
- Persistent generation (contains meta information like class, method details)
Update: The Persistent generation (PermGen) zone was removed from the Java SE 8 feature.
In the next section we'll see how garbage collection works in Java
View Original
Introduction to Java Garbage collection (translated)