What is the basic principle of the garbage collector? Can the garbage collector reclaim memory right away? Is there any way to actively notify the virtual machine for garbage collection

For the GC , when the programmer creates an object, the GC begins to monitor the address, size, and usage of the object. Generally, GC records and manages all objects in the heap in a directed graph manner . In this way it is determined which objects are " reachable " and which objects are " unreachable " . When the GC determines that some objects are " unreachable " , the GC has the responsibility to reclaim the memory space. Can.

 

Programmers can manually execute System.gc() to notify the GC to run, but the Java language specification does not guarantee that the GC will be executed.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326322571&siteId=291194637