What is the purpose of garbage collection in 1.Java? When does garbage collection take place?
The purpose of garbage collection is to identify and discard objects that the app is no longer using to free and reuse resources.
What will 2.system.gc () and RUNTIME.GC () do?
These two methods are used to prompt the JVM for garbage collection. However, starting or delaying a garbage collection immediately depends on the JVM.
When is the 3.finalize () method called? What is the purpose of the destructor (finalization)?
When the garbage collector (garbage Colector) decides to recycle an object, it runs the Finalize () method of the object but unfortunately in Java, if the memory is always sufficient, garbage collection may never occur, meaning that filalize () may never be executed , apparently counting on it to do the finishing work is unreliable. So what exactly does finalize () do? Its main purpose is to reclaim the memory of special channel applications. Java programs have garbage collector, so in general memory problems don't bother programmers. But there is a jni (Java Native Interface) called Non-java Program (C or C + +), and finalize () works to reclaim this part of memory.
4. If the object's reference is set to NULL, will the garbage collector immediately release the memory occupied by the object?
No, in the next garbage collection cycle, this object will be recoverable.
What is the structure of the 5.Java heap like? What is the permanent generation in the heap (Perm Gen space)?
The JVM's heap is the run-time data area, and all instances and arrays of classes are allocated memory on the heap. It is created when the JVM is started. The heap memory that the object occupies is reclaimed by the automatic memory management system, which is the garbage collector.
Heap memory is made up of surviving and dying objects. The surviving objects are accessible to the app and are not garbage collected. The object of death is the object that the app is inaccessible and has not been reclaimed by the garbage collector. Until the garbage collector reclaims these objects, they will occupy the heap memory space.
6. What is the difference between a serial (serial) collector and a throughput (throughput) collector?
The throughput collector uses a parallel version of the new generation garbage collector, which is used for medium-sized and large-scale data applications. The serial collector is sufficient for most small applications, which require about 100M of memory on modern processors.
7. In Java, when can objects be garbage collected?
This object can be recycled when the object becomes inaccessible to applications that currently use the object.
Is there a garbage collection in the permanent generation of 8.JVM?
Garbage collection does not occur in a permanent generation, and if it is permanently full or exceeds the threshold, a full GC is triggered. If you look closely at the output of the garbage collector, you will find that the permanent generation is also recycled. This is why the correct permanent generation size is very important for avoiding full GC. Please refer to the following Java8: from the permanent generation to the Meta data area
(Note: The permanent generation has been removed from the Java8 and a new native memory area called the metadata area has been added)
Interview Questions-java Basics-garbage collection