Java Finalize method Summary, GC execution finalize processCategory: Java2013-10-06 16:42 73 people read Comments (0) favorite reports FinalizejavajvmDirectory (?) [+]
Note: The purpose of this article is not to encourage the use of the
When the garbage collector wants to reclaim objects, you first call the Finalize method of the class (you can write the program to validate the conclusion), and the normal Java-written class does not need to overwrite this method, because object has
the Java Finalize method usestags: JAVAAPPLETOBJECTWIZARDJVM Work2011-08-21 11:37 48403 People read comments (5) favorite reports Classification:Java (+)"JAVA programming ideas":Java provides the finalize() method, which is called Finalize ()
Note: The purpose of this article is not to encourage the use of the Finalize method, but to roughly clarify its role, problems, and the process by which the GC performs finalize.
1. The role of Finalize
Finalize () is the protected
Final keyword:The final keyword usually refers to "immutable", and the use of "cannot be changed" can be done for two reasons: design or efficiency.Final can modify variables, methods, and classes.first, final variablesA domain that is both static
Before explaining the use of finalize (), there are a few points to be set about the Java garbage collector:
"Object can not be garbage collected": Java garbage collection follows a feature, that is, can not be recycled without recycling.
From: http://www.cnblogs.com/lzhdim/archive/2009/11/04/1595845.html
Before learning about finalize and dispose, we need to understand two concepts: managed resources and non-commissioned resources.A. managed resources generally refer to the memory
The last post talked about the optimization of the garbage collector. After a long time, I didn't continue to talk about finalize (in fact, this is a bit of a problem with GC ). Today, let's take a look at the performance topics related to finalize
1. The role of Finalize
Finalize () is the protected method of object, which can be overridden by subclasses to implement resource cleanup, which is called by the GC before it reclaims the object.
Finalize () does not correspond to
This is the best article I have read about finalize in Java.
Finalize () in Java ()
When the garbage collector wants to recycle objects, it first needs to call the Finalize method of this class (you can write a program to verify this conclusion).
Finalfinal-modifier (keyword) If a class is declared final, it means that it can no longer derive a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared abstract and declared final. Declaring variables or
Final-modifier (keyword) if a class is declared as final, it means that it cannot generate a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared both abstract and final. Declare variables or methods as final
My previous blog:System.GC () and-XX:+DISABLEEXPLICITGC startup parameters, and Directbytebuffer memory release when discussing how to reclaim out-of-heap memory, mention "NiO in direct The release of memory is not through Finalize (), because
Directory
Basic Preparation related knowledge
object's destruction process
An example of an object rebirth
The finalize execution order of the object
When and how to use Finalize
Reference
Basic Preparation related knowledge
1 Java GC is
Function
Understanding Finalize ()-destructor substitution
In many ways, Java is similar to C + +. Java syntax is very similar to C++,java classes, methods, and data members; Java classes have constructors; Java has exception handling.
The following are the descriptions in the JDK:Called by the garbage collector on a object when garbage collection determines that there is no more references to the O Bject. A Subclass overrides the finalize method to dispose of the system resources
Basic Preparation related knowledge1 Java GC is only responsible for memory-related cleanup, and all other resource cleanup must be done manually by the programmer. Otherwise, it can cause a resource leak, which could cause the program to crash.2
Programmers are aware of the importance of initialization, but often forget the same important cleanup effort. After all, who needs to clear an int? However, when using a library, it is not always safe to "discard" an object after it has been
Java in the final, finally, finalize the difference and usage, troubled a lot of learners, the following we have some discussion on this issue, I hope that everyone's learning has helped.Method/Step
1Simple difference:Final is used to
The similarities between finalize and dispose (bool disposing) and dispose () are as follows:
These three services are designed to release unmanaged resource services.
Differences between finalize and dispose () and dispose (bool disposing:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.