JVM garbage collection history

I saw an article on the Internet about the history of garbage collection and brought it here:

Why is there GC

? I sometimes hear C++ programmers say that we are a generation spoiled by GC. This is indeed the case. When I was learning the GC algorithm, the first question in my mind was why I needed something like GC. Explain that I have taken GC for granted.

In a word: in a world without GC, we need to manually manage memory, and manual memory management is purely technical and error-prone.

Since most of the programs we write are designed to solve real-world business problems, why don't we automate this purely technical activity? But automation comes at a cost. This is my personal understanding and does not represent John McCarthy's own.

The definition of "garbage"

First , we have to give a definition of "garbage" in order to recycle it. The definition given in the book: > The objects allocated to the heap that cannot be referenced by the program are called inactive objects, that is, dead objects, and we call them "garbage".

Definition of GC

Since we want to make memory management automatic (only use memory, regardless of memory reclamation), we have to do two things: > 1. Find the garbage in the memory space > 2. Collect garbage so that the programmer can Use this part of the space again [1] As long as the program that satisfies these two functions is the GC, whether it is in the JVM or in the Ruby VM.

But these are just two requirements, and they do not explain more specific issues such as when GC should look for garbage, when to collect garbage, etc. Various GC algorithms are used to deal with these more specific problems.

The history of GC

John McCarthy is the father of Lisp and artificial intelligence. At the same time, he is also the father of GC. In 1960, he published the GC algorithm for the first time (in fact, a euphemistic proposal) in his paper.

The mark-sweep algorithm was proposed by John McCarthy in 1960
Reference counting was proposed by George E. Collins in 1960. This algorithm has a circular reference problem, and Harold McBeth pointed out in 1963.
The replication algorithm was proposed by Marvin L. Minsky in 1963. The author of
"Garbage Collection" believes that

since the GC algorithm was first released 50 years ago, many researchers have conducted various studies on it, so many GC algorithms have also been released. . [2] But in fact, these algorithms are just a combination or application of the three algorithms mentioned above. It can also be said that when the GC replication algorithm was born in 1963, the fundamental content of GC has been completed. [3]
Then what about the generational garbage collection we often hear about? Here's what the author says: > People have drawn a lesson from many program cases: "Most objects become garbage immediately after being created, and very few objects live very long". The generational garbage collection uses this experience to introduce the concept of "age" into the object. The age of the object that survives a GC is 1 year old. [4]

In the generational garbage collection, objects are classified into several generations, and different GC algorithms are used for different generations. We call the newly generated objects as new generation objects, and objects that reach a certain age are called old generation objects. [5]
Well, now I finally know why I need to be generational. My conclusion is: Classify objects according to their survival probability. For objects with a longer survival time, you can reduce the time of scanning "garbage" to reduce GC. frequency and duration. The fundamental idea is to classify objects, so that different garbage collection algorithms can be used for each classification, so as to make use of the advantages and avoid disadvantages of each algorithm.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326709826&siteId=291194637