Stack
When a function or a method calls another function which in turns calls another function etc., the execution of all those functions remains suspended until the very last function returns its value.
This chain of suspended function calls is the stack, because elements in the stack (function calls) depend on each other.
The stack is important to consider in exception handling and thread executions.
Heap
The heap is simply the memory used by programs to store variables.
Element of the heap (variables) have no dependencies with each other and can always be accessed randomly at any time.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1698901/viewspace-612076/ ,如需转载,请注明出处,否则将追究法律责任。