Java basics-005, java-005
27. Purpose of garbage collection in Java and timing of garbage collection
The purpose of garbage collection is to identify and Discard unused objects to release and reuse resources.
If the object reference is set to null, the garbage collector does not immediately release the memory occupied by the object.
When garbage collection depends primarily on JVM. Refer to the http://www.cnblogs.com/lrh-xl/p/5292495.html
28. System. gc () and Runtime. gc ()
These two methods are used to prompt the JVM to perform garbage collection. However, whether to start garbage collection immediately or delay depends on the JVM.
The actions of these two methods are essentially the same.
29. finalize () method
When the Garbage Collector decides to recycle an object, it will run the finalize () method of the object. However, in Java, if the memory is sufficient, garbage collection may never be performed, that is, finalize () it may never be executed. Obviously, it is unreliable to close the work. (The time for garbage collection depends on the JVM type, the garbage collection algorithm adopted by JVM, and the memory allocation and collection policy ). the fianlize () method is mainly used to reclaim memory applied by special channels. java programs have garbage collectors, so there is usually no need for programmers to worry about memory problems, but there is a JNI (Java Native Interface) that calls non-Java programs (C/C ++ ), finalize () is to recycle this part of memory.
30. Java heap and permanent generation
The JVM heap is the runtime data zone, and all class instances and arrays are allocated memory on the heap. it was created at JVM startup. the memory occupied by objects is collected by the automatic memory management system, that is, the garbage collector.
Heap memory is composed of surviving and dead objects. The surviving objects are accessible to applications and will not be recycled, the dead objects are objects that are inaccessible to the application and are not recycled by the garbage collector. They occupy the memory until the Garbage Collector recycles these objects.
Understanding