Some summary of the Finalize () method of Java garbage collector and class

xiaoxiao2021-04-09  524

Some summary of the Finalize () method of Java garbage collector and class

Excerpt from the website www.matrix.org.cn

1. The work goal of the garbage collector is to recycle the memory space of the useless object, thereby avoiding the production of memory leaks, saving memory resources, avoiding the crash of the program code. 2. The garbage collector determines whether an object's memory space is useless: if the object cannot be referenced by any "activity part" in the program, we said that the memory space of the object is useless. The so-called "part of the activity" means the call of some part of the participating program in the program. During the execution process, it has not yet been executed. 3. The garbage collector thread is running as a low priority thread, but when the amount of memory available in the system is too low, it may burst into rescue memory resources. Of course, its execution is also unpredictable. 4. The garbage collector cannot be enforced, but programmers can recommend execution of garbage collectors by calling the System. GC method. 5. You cannot guarantee that a useless object will be collected by the garbage collector, nor guarantee that the garbage collector will be executed in a Java language code. Therefore, the memory space assigned in the program execution may remain until the program is executed, unless the space is reassigned or recycled by other methods. It can be seen that it is impossible to completely initially root the production of memory leakage. But please don't forget that Java's garbage collector has made the programmer from the heavy work of manually recovering memory space. Imagine a programmer to write a 100,000-row statement with C or C , then he will fully understand the advantages of Java's garbage collector! 6. There is also no way to predict which one will be first collected in a group of garbage collector collection standards. 7. The loop reference object does not affect its garbage collector. 8. The garbage collector can be hinted to collect this object by initializing the reference variable of the object to the NULL value. At this time, if the object is connected to an event listener (typical AWT component), it is still not a collected. Therefore, before setting a reference variable as a null value, it should be noted whether the object to which the reference variable points to be listened. If there is, you should first remove the listener before you can assign a null value. 9. Every object has a Finalize () method, which is inherited from the Object class. 10. Finalize () method is used to recover system resources other than memory, just like file processors and network connectors. The order in which the method is called and the order of the object used to call the method is independent. In other words, the order and method of the method and the actual call order of the method and method of the method are not coheed. Note that this is just the characteristics of the femalize () method. 11. Each object can only call the femalize () method once. If an exception is generated when the Finalize () method is executed, the object can still be collected by the garbage collector. 12. The garbage collector tracks each object, collects those who are not reachable (that is, the object is not called any "live portion" that is active, reclaiming its own memory space. However, when garbage collection, the garbage collector calls the Finalize () method, making the non-reachable object "recovered" again by allowing other objects to "recover" as the reachable object. Since each object can only call a femalize () method, each object is only "recovered" once. 13. The Finalize () method can be explicitly called, but it cannot be garbage collection.

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

New Post(0)