In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "JVM basic garbage collection algorithm". In daily operation, I believe many people have doubts about JVM basic garbage collection algorithm. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "JVM basic garbage collection algorithm". Next, please follow the editor to study!
Garbage collection algorithms can be divided from different angles:
According to the basic recycling strategy
Reference count (Reference Counting):
A relatively old recycling algorithm. The principle is that this object has a reference, which increases a count, and deletes a reference reduces a count. For garbage collection, only objects with a count of 0 are collected. The deadliest thing about this algorithm is that it can't handle circular references.
Mark-clear (Mark-Sweep):
The implementation of this algorithm is divided into two stages. The * * phase marks all referenced objects from the reference root node, and the second phase traverses the entire heap to clear the untagged objects. This algorithm needs to pause the entire application and generate memory fragmentation at the same time.
Copy (Copying):
This algorithm divides the memory space into two equal regions, using only one of them at a time. When garbage collection, traverse the current use area and copy the objects in use to another area. The secondary algorithm only deals with the objects in use each time, so the replication cost is relatively small, and the corresponding memory can be demarcated after the copy, without the problem of "fragmentation". Of course, the disadvantage of this algorithm is also obvious, which requires twice the memory space.
Tag-organize (Mark-Compact):
This algorithm combines the advantages of "mark-clear" and "copy" algorithms. It is also divided into two phases, the * phase marks all referenced objects from the root node, and the second phase traverses the entire heap, clearing the untagged objects and "compressing" the surviving objects into one of the pieces of the heap and discharging them sequentially. This algorithm not only avoids the fragmentation problem of "mark-clear", but also avoids the space problem of "copy" algorithm.
Divided according to the way it is treated by regions.
Incremental collection (Incremental Collecting): real-time garbage collection algorithm, that is, garbage collection while the application is in progress. For some reason, the collectors in JDK5.0 do not use this algorithm.
Generational collection (Generational Collecting): a garbage collection algorithm based on the analysis of the life cycle of objects. The objects are divided into the young generation, the old generation and the persistent generation, and the objects with different life cycles are recycled using different algorithms (one of the above methods). Today's garbage collectors (starting with J2SE1.2) use this algorithm.
Divided by system thread
Serial collection: serial collection uses a single thread to handle all garbage collection work because it does not require multithreaded interaction, is easy to implement, and is more efficient. However, its limitations are also obvious, that is, the advantage of not being able to use multiprocessors, so this collection is suitable for single-processor machines. Of course, this collector can also be used on multiprocessor machines with a small amount of data (about 100m).
Parallel collection: parallel collection uses multithreading to deal with garbage collection, so it is fast and efficient. And theoretically, the more the number of CPU, the more it can reflect the advantages of parallel collectors.
Concurrent collection: compared with serial collection and parallel collection, the first two need to pause the entire running environment during garbage collection, and only the garbage collection program is running, so the system will have an obvious pause during garbage collection. and the pause time is longer because of the larger the heap.
At this point, the study on the "JVM basic garbage collection algorithm" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.