on the characteristics of Java garbage collection mechanism:
1. The goal of the garbage collection mechanism is to reclaim the memory space of useless objects (remember: not objects), which is the memory space of the JVM heap memory. Garbage collection only reclaims memory resources, for those physical resources, such as database connection, SOCKET,I/O stream and other resources incompetent, we have to shut down the recovery.
2. In order to speed up the garbage collection mechanism to reclaim the memory space occupied by those useless objects, we can say that the reference variable of the object is placed in null (remember: the garbage collection mechanism does not execute immediately when NULL is placed).
3. Potential drawbacks of the garbage collection mechanism its overhead can affect performance. The Java virtual machine must keep track of the objects that are useful in the program to determine which objects are useless and free up memory space for those useless objects. This process takes the processor time.
4. The unpredictability of garbage collection. We can recommend that the system be garbage collected through the GC () method of the runtime object or System.GC (), but we cannot precisely control the garbage collection mechanism's operation.
Summary: When writing a program, one of the basic principles is: do not refer to objects that are no longer needed. If you keep a reference to them, the garbage collection mechanism temporarily does not reclaim the memory they occupy, the system has less memory available, and when the system has less available memory, the garbage collection mechanism executes more frequently, resulting in degraded system performance.
The characteristics of Java garbage collection mechanism