1. Use new to create objects, allocate object space in heap memory, initialize;
2. Define a local variable in the method stack and eat a reference to the object in the heap memory;
3. The method executes the return, the stack memory is freed automatically, the local variable destroys;
4. If the heap in-memory object does not have a variable to reference it, becomes garbage, has garbage collector reclaimed, frees up the occupied heap memory
5.Java garbage collector
(1) The Java Runtime System has a garbage collection thread responsible for purging objects that are no longer used, commonly known as garbage collector;
(2) The garbage collector scans the memory periodically, marking the objects used, and clearing unmarked objects after the possible path scan ends
(3) The objects to be recycled are:
A. An object that is no longer referenced by any variable;
B. The reference variable is automatically discarded;
C. Artificially placing a reference variable as null
4.Java Basics: Memory management mechanism for Java objects