原文地址 https://javapapers.com/java/j...java
In Java, allocation and de-allocation of memory space for objects are done by the garbage collection process in an automated way by the JVM. Unlike C language the developers need not write code for garbage collection in Java. This is one among the many features that made Java popular and helps programmers write better Java applications.
在 Java 中,對用於存儲對象的內存空間的分配和回收是 JVM 經過垃圾收集器自動完成的。與 C 語言不一樣,Java 編程者不須要手工寫垃圾回收的語句。這是 Java 之因此變得流行的衆多因素之一,它讓編程者能寫出更好的 Java 應用。編程
This is a four part tutorial series to know about the basics of garbage collection in Java,
本系列文章一共包含四篇,介紹 Java 垃圾回收的基本知識:segmentfault
This tutorial is the first part in the series. It will explain the basic terminologies like JDK, JVM, JRE, HotSpot VM then understand the JVM architecture and Java heap memory structure. It is important to understand these basic things before going into the Garbage collection tutorial.
本文是系列中的第一部分,將介紹一些基本的技術名詞好比 JDK、JVM、JRE、HotSpot VM,以幫助讀者瞭解 JVM 的架構和 Java 堆內存的結構。想要深刻了解垃圾回收的話,瞭解這些基本概念十分重要。架構
Each JVM implementation may be different in the way the garbage collection principles are implemented. Prior to SUN takeover Oracle had JRockit JVM and after takeover it got the HotSpot JVM. Presently Oracle maintains both the JVM implementations and it has declared that over a period these two JVM implementations will be converged to one.
不一樣的虛擬機實如今垃圾回收的實施原則上有所不一樣。在 SUN 被 Oracle 收購以前,其產品是 JRockit 虛擬機,以後是 HotSpot 虛擬機。目前 Oracle 同時維護這兩個虛擬機實現,並計劃在未來某個時間將二者結合到一塊兒。app
HotSpot JVM is available as a core component as part of the standard Oracle SE platform. In this garbage collection tutorial, we will see the garbage collection principles based on the HotSpot Virtual Machine.
HotSpot 虛擬機是標準的 Oracle SE 平臺的核心部分。在本教程中,咱們將瞭解基於 HotSpot 虛擬機的垃圾回收原則。工具
Following diagram summarizes the key components in a JVM. In the JVM architecture, two main components that are related to garbage collection are heap memory and garbage collector. Heap memory is the runtime data area where the instances will be store and the garbage collector will operate on. Now we know how these things fit in the larger scheme.
下圖大體展現了 JVM 的關鍵部件。在 JVM 架構中,兩個部件與垃圾回收相關:堆內存(Heap Memory)和垃圾回收器(Garbage Collector)。堆內存是存放數據的內存區域,用來在運行期間保存對象實例,垃圾回收器的工做也是在堆內存當中進行的。如今咱們已經在大尺度方面瞭解了它們之間是如何配合的。this
It is essential to understand the role of heap memory in JVM memory model. At runtime the Java instances are stored in the heap memory area. When an object is not referenced anymore it becomes eligible for eviction from heap memory. During garbage collection process, those objects are evicted from heap memory and the space is reclaimed. Heap memory has three major areas,
理解堆內存在 JVM 內存模型中的角色是很是必要的。Java 對象實例在程序運行期間存儲在堆內存中。當一個對象再也不被外部引用時,它就有了被回收的資格。在垃圾回收處理期間,此類對象都會被回收,其佔用的內存會被釋放。堆內存由三個主要區域組成:spa
Young Generation
(新生代)操作系統
Update: Permanent Generation (Permgen) space is removed from Java SE 8 features.
更新:從 Java 8 開始,堆內存模型中再也不包含永久區。翻譯
In this next part of this tutorial series we will see about how garbage collection works in Java.
在下一篇文章中,咱們將瞭解垃圾回收的運行機理。