“This is the 20th day of my participation in the August Gwen Challenge.

🔉 introduction

Before we garbage collection details, but how specific recycling, but did not mention, today we will introduce one by one: HotSpot in the garbage collector.

⭐️ Classic garbage collector

If the previous introduction was all about methodology, this article is about the practical part of the methodology – the concrete garbage collector. The following figure shows seven garbage collectors, which can be used in different generations and can be used together. Learn more about the goals, principles, features, and usage scenarios of these garbage collectors with me.

Need to note that no matter how we compare, we can not find a “universal” garbage collector, but each garbage collector applies to different scenarios, different characteristics of it, so we have to choose the best garbage collector according to the appropriate scenario, this is necessary to us ah, hee hee.

🌟 Serial collector

This collector is one of the oldest and most basic, and its name indicates that it is a single-threaded collector. If you’re using it for garbage collection, agree to suspend all user threads until the collection is complete. To resist such unpredictable and uncontrollable behavior, think about it. You are happily playing LOL, 5V5 team, and the virtual machine says: You can pause the game, I have to do garbage collection, can you bear it? Even if you can, you know when it’s over? You don’t know, so it’s not acceptable.

Well, you might say, gee, this garbage collector is good garbage, but the fact is that it’s still the default garbage collector for Hotspot to run in client mode, and it certainly has some advantages over other garbage collectors in that it’s simple and efficient, it’s the least expensive of all garbage collectors and there’s no overhead of thread interaction, Concentrate on garbage recycling can naturally achieve higher recycling efficiency.

This method applies to desktop applications. Generally, the memory allocated to VMS by these applications is not very large and the reclamation time is less than 100ms. Therefore, it is acceptable as long as the reclamation is not frequent.

🌟 PraNew collector

This collector is similar to Serial in that it can be considered a multithreaded version of Serial and shares a considerable amount of code in its implementation. It doesn’t seem like much of an innovation, but it works with CMS, which is what CMS is, and CMS is also a garbage collector, which is a game-changer in highly interactive applications, and for the first time allows the garbage collector to work (basically) at the same time as the user’s thread. Figure is as follows:

📝 digression

What is the meaning of human life? Or what is the meaning of all living things in general? To answer this question means to be religious. So what exactly is the point of asking this question, you may ask? I answer that any man who regards his own life and that of his fellow as meaningless is not only unhappy, but almost unfit for existence.

Those who do not respect, trample, destroy the lives of others or their own people, do not deserve respect for his life.