“This is the 13th day of my participation in the August More Text Challenge. For details, see: August More Text Challenge.”

☀ ️ introduction

Last time we talked about the reachable analysis algorithm, as long as the unreachable object will be recycled, is that directly sentenced to death, is there any chance of reprieve? Well, today we’re going to talk about that.

☀️ Object’s decision

Even if it is marked as unreachable, it is not immediately brought to court, there is a judgment. To declare an object dead, you have to go through at least two processes: if the object doesn’t have a reference chain in the reachabability analysis, you tag it once, and then you filter it further. What do you see? Finalize () method is necessary for this object. If the object does not override the Finalize () method, or if the method has been called, then there is no need to execute in either case.

❄ ️ finalize () method

If it is determined that it is necessary to execute finalize() method on the object, the object will be put into the queue of an F-Queen. Later, the virtual machine will send a little brother 😮, a Finalize () thread with low scheduling priority, to execute finalize() method of the object itself. It should be pointed out that the virtual machine only triggers the execution of this method, and does not wait for it to happen, just to make sure that in case your little brother gets drunk and wants to be lazy, all the other objects in the QUEUE of f-Queen are waiting, which in the extreme would cause the entire recycling subsystem to crash.

❄️ Finalize () Method function (Interview question)

Finalize () method is the last chance for the object and the death to survive. If the relationship is established with any object on the reference chain of GC Roots during this period, the collection waiting to be collected will be removed during the second marking, which proves that you are a good person, but you will not be issued a good person card, but a quasi good person card. Once it is marked next time, I wouldn’t have been able to execute the self-help.

☀ ️ knock on the blackboard

It should be noted that everything that Finalize () can do can be done better with try-finally, so it is recommended to forget this method.

☀ ️ digression

Most of the time, the troubles in our life are caused by the dissatisfaction with their own state, feel ashamed of themselves, and refused to change fundamentally, so we have to pass the complaint on her husband, family and parents, the common words are: how people how, so give you 16 words of truth is:

  • Solid endeavour
  • Practical to assume
  • Pay the harvest
  • Ordinary real