First, stack
1. Different ways of disappearing: Method variables are released as the Stack method is released
2. The storage location is different, the default replication processing mechanism is different: will not give the property of the method to the initial value, it can be understood that the properties of the method in the class is a local variable, the local variable cannot be attached to the initial value, the state of the class is represented by the values of the member variables of the class, so the class is is stateless, and the stored space is within the stack method area.
Second, the heap
1. member variables will not disappear with no reference, waiting for the JVM's garbage collector to recycle, that is, the JVM's GG
2. The member property of the instantiated object is appended with the initial value
3. As long as it is new, the memory will open up the space
4. Erase the reference, even if the reference is named NULL, as follows:
Packagecom.dreamly.day01;/** * @authordreamly **/ Public classArrayTest01 { Public Static voidMain (string[] args) {int[] x=New int[3]; x[0]=2; X=NULL;//erases the connection to the instance object, that is, the address value is not saved. }}
The difference between heap and stack of Java learning