I have written a lot of small programs, but I still know little about memory allocation. I learned Java, and I have some basic knowledge about it, so I can write it out and forget it.
For some primitive types, we call them value types. Normally, the allocated memory space is in the stack, while for the types created through new, they are in the heap. It is better to use code to explain.
Public String cursor; Public int teachage; visitor = new visitor ();
For the above Code, cursor and teachage are in the stack, visitor is in the stack, and the visitor object is in the heap. I am confused myself, sorry. Lazy, don't want to draw a picture, that is, the visitor in the stack points to the memory allocated for the visitor in the heap. This sentence is clear.
Memory Allocation is still a problem for me. I also need to learn the garbage collection mechanism in Java. Currently, I know the garbage collection mechanism as follows: Java has a garbage collector, periodically scan the "Empty memory", that is, the memory with no pointer pointing to, and then release it. It's not enough to simply understand it! Not enough...