11th questions (garbage collection), garbage collection
1. Runtime class
Each Java application hasRuntime
Class instance, so that the application can be connected to the running environment. You can usegetRuntime
Method to obtain the current runtime.
Applications cannot create their own Runtime instances.
public static Runtime getRuntime()
-
Returns the runtime objects related to the current Java application.
Runtime
Most methods of the class are instance methods and must be called based on the current runtime object.
-
-
Return Value:
-
Related to the current Java application
Runtime
Object.
public long freeMemory()
-
Returns the amount of free memory in the Java Virtual Machine. Call
gc
Method may cause
freeMemory
The returned value is increased.
-
-
Return Value:
-
The approximate total amount of memory available for future object allocation, in bytes.
-
(A error)
-
public void gc()
Run the garbage collector. Calling this method means that the Java Virtual Machine has made some efforts to recycle unused objects, so that the memory occupied by these objects can be reused quickly. When the control is returned from the method call, the virtual machine has done its best to recycle all discarded objects.
Namegc
Indicates the "Garbage Collector ". The virtual machine automatically executes the Recycle Process in a separate thread as needed, or even explicitly callsgc
Method.
Method System. gc () is a traditional and convenient method to call this method.
Gc is a non-static method,
Therefore, Runtime. getRuntime (). gc ();
B Error
Ii. System class
public static void gc()
Run the garbage collector.
Callgc
The method implies that the Java Virtual Machine has made some efforts to recycle unused objects so that they can quickly reuse the memory currently occupied by these objects. When the control is returned from the method call, the virtual machine has done its best to reclaim space from all discarded objects.
CallSystem.gc()
It is actually equivalent to calling: Runtime. getRuntime (). gc ()
Select E
3. The growHeap () function cannot be found in the API. I wonder if it does not exist.
Iii. java garbage collection (gc) Mechanism
Http://www.cnblogs.com/aigongsi/archive/2012/04/06/2434771.html
Http://www.cnblogs.com/aigongsi/archive/2012/04/13/2446166.html