Why Java uses garbage collection and C + + does not, because in Java, all object variables are references, when a reference is overwritten by a new object, there is no reference to the original object, the object is "out of control."
In C + +, unless you use a special symbol & indicate that the variable name is a reference, the variable refers to the object, the object has a life cycle, and at the end of the lifecycle, the destructor is called to complete the memory release, whereas the C + + Reference object must point to the object, and it is clear that it should be referenced before it is declared Even if the reference later points to another variable, it does not cause the original object reference number to be 0, so that its destructor can still be called (through a variable pointing to the object), and the Java reference already points to other objects, so the address of the original object cannot be obtained, which is why Java has put the data in the heap.
There is no consideration of the c++new situation.
RAII Transcendental function declaration period:
About why Java requires garbage collection