Different memory segments
During the runtime of an application, three main kinds of memory segments are used depending on the behavior:
Stack memory
Heap memory
Register memory
Stack memory
All auto variables and runtime allocation during processing will be stored in the stack memory segment. The garbage collector deallocates the memory after use. So, there is no manual memory management process associated with the stack memory.
However, extensive use of auto variables also may cause memory errors. This is the reason we have already discussed why minimizing unnecessary auto variable declarations is necessary.
Stack memory is also used to execute program instructions. Each instruction is broken down into a single operation and put into a stack by the interpreter. Then, a recursive procedure is used to execute all the instruction stacks and return the result.
Let's have a look at how stack memory works for objects and primitives:
public class ExampleClass { public ExampleClass() { int bitMapCount...