Introduction to Java Garbage collection (translated)

Source: Internet
Author: User
Tags java se

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,

    1. Introduction to Java Garbage collection
    2. How does Java garbage collection work?
    3. Types of Java garbage collector
    4. 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,

    1. Young Generation Generation
      1. Eden Zone (any instance enters the run-time memory area)
      2. S0 survivor Area (a longer instance from Eden Zone to S0)
      3. S1 survivor Zone (a longer instance from the S0 zone to S1)
    2. Old generation (instance promoted from S1)
    3. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.