Critique of garbage collection mechanism

zhaozj2021-02-16  55

Critique of garbage collection mechanism [original] Myan 2004-05-26

Published this article in Java, seems to have a scorpion. In fact, the GC is a GC mechanism in all the characteristics of all a new generation of languages, Python, Eiffel, C #, Roby, etc. use the GC mechanism. But since the GC in Java is most famous, it should naturally be resistant to the sky. This short message is from Comp.lang.java.Programmer with a big debate that occurs on Comp.lang.c , supports C and Java's two different forces to launch the first conflict in the new century, with the stickers more than 350, The two factions have a famous angular blanket. The C camp is the main reason for Pete Becker, ACM member, Dinkumware Ltd. Technology deputy director. This king is proficient in C and Java, developed the core class library of two languages, but it is very flying to C , but it is very unsolute for Java. When you talk about Java, it is okay. Once some people dare to use Java to criticize C , I can't help but jump, with the perseverance and the big fearless spirit and the opponent, the tongue war, even if only one left People also have to serve in the end. This gods are really few! I am really strange that he is on the usenet, don't you worry? His boss p.j. Plauger is so wide? The Java array protagonist is a brother of the net name Razzi. In addition, SUN has a famous Peter Van Der Van Der Van Der Van Der Van Der Van Der Van Der Van Der Van Der, and the words are lingering, inch soil must strive, plus more people, and occupy the advantage. Although there are many C camps, most of them don't have pete, such as Greg Comeau, Comeau's boss, every time I come to a word, I can't help Pete is too busy. However, since the C camp, an unknown kid, the net name Courage (courage), and the criticism of the Java GC mechanism was launched. The C camp is in full attack, the Java camp is tired of defending, only in the court: "You have no evidence, no statistics", the situation is very passive. Waste collection (GC) is not used by java fans to show off, proud? How did it become weak? I am puzzled, I will find it in this way. First, Java Swing inventory is very clear in a large number of resource leaks, which is very clear, called BUGS, is being amended. However, it seems that the problems here are probably not only the negligence of the writers of the library, but the root may be the deep mechanism, and may not be able to solve it easily. It is not good to hurt the bones. However, this problem is not that, the C camp feels that if the other party's weakness attack is seized, even if it takes up the wind, there is no convincing. Who has no shortcomings? So, in turn, violently attacking the Java camp feeling the most proud of the Java's GC mechanism itself. First, think about it, Memory Leak means something. In C , New Objects have no delete, which results in Memoryleak. But C has long had a way to overcome this issue - Smart Pointer.

By using exquisite auto_ptr and various STL containers in the standard library, there are, for example, the four smart points in the Boost library (almost the standard library), C programmers learn the latest information for a week, You can shoot your chest: "I wrote the program without Memory Leak!". In contrast, Java seems to be better, because you don't have to consider what special mechanisms from the beginning, boldly, new, self-owned GC to clean up the resilience. Java's GC is actually a stand-alone thread in the JVM, using different algorithm policies to collect the memory occupied by the spam objects in HEAP. However, in general, the priority of the GC thread is relatively low, and only when the current program is idle, it will be scheduled to collect garbage. Of course, if the JVM feels tight, JVM actively calls GC to collect garbage to get more memory. Note that the timing of Java's GC work is: 1. The current program is not busy, there is free time. 2. Insufficient free memory. Now we consider a common situation, the program is running in nervous, there is no idle time to run GC, and the machine memory is very large, and JVM has not felt insufficient memory, what is the result? By the way, the GC is similar to the dummy, and the call is not called. So, memory is constantly being swallowed, and those that have already used unexpected garbage still sleep in the valuable memory. For example: class badgc {public void job1 () {string garbage = "i am A Garbage, And Just Sleeping in Your Precious Memory," "How do you think you can DEAL with me? Daydreaming! Haha !!!"; ...} public void Job2 () {...} ... ... public void Job1000 () {...} public static void main (string [] args) {bgc = new badgc (); BGC. Job1 (); bgc.job2 (); ... bgc.job1000 ();}} running, although the Garbage object is not used after leaving JOB1 (), it is no longer used. But because the program is busy, the memory is still enough, so the GC will not schedul, Garbage will not be recycled until the program is running to BGC.JOB1000 (), I still laugh at you. No need! Ok, I admit that this program is stupid. But don't think that this is just theoretical assumption, just contrary, most practical Java programs have similar effects. That's why Java programs are mad memory, and it seems that there is not enough memory to eat. You spend a big bank to raise memory from 128 to 256, then raise to 512, the result is that once the complex task is performed, the memory is still easy to fill, and more of these memory is just used to install garbage, the GC is still not I can't call the face. Wait until your memory is finally interspersed, GC is late, clean up the residue. And the way GC work is also very good, one method is to reclaim all garbage once there is a chance to recover memory.

转载请注明原文地址:https://www.9cbs.com/read-21920.html

New Post(0)