-
Stack and Heap Memory RegionsModeling/Architecture 2020. 2. 26. 23:36
1. Overview
2. Stack
2.1 What is allocated in Stack
- Methods are called
- Arguments are passed
- Local variables are stored
- Stack + Instruction Pointer = State of each thread's execution
2.2 Example
2.3 Properties
- All variables belong to the thread executing on that stack
- Statistically allocated when the thread is created
- The stack's size is fixed, and relatively small which depends on the specific platform
- If our calling hierarchy is too deep. We may get a StackOverflow Exception.
3. Heap
3.1 What is stored in Heap
- Objects which are anything created with the new operator
- Members of classes
- Static variables
3.2 Features
- Governed and managed by Garbage Collector
- Objects stay as long as we have a reference to them
- Members of classes exist as long as their parent objects exist which means the same life cycle as their parents
- Static variables stay forever through the entire application lifetime
- References can be allocated on the stack, or heap if they are members of a class
- Objects always allocated on the heap
4. Summary
Heap (shared) Stack (exclusive) Objects Local primitive types Static variable Local references Class members 5. Reference
https://www.geeksforgeeks.org/stack-vs-heap-memory-allocation/
https://gribblelab.org/CBootCamp/7_Memory_Stack_vs_Heap.html
'Modeling > Architecture' 카테고리의 다른 글
Representational state transfer (REST) API (0) 2020.03.08 Resource Sharing, Critical Sections, and Atomic operations (0) 2020.02.27 Relationship of Thread, Process, OS, and Memory (0) 2020.02.04 Difference between Extract, Transform and Load(ETL) and Enterprise Application Integration(EAI) (0) 2019.09.29 Service-Oriented Architecture(SOA) and Microservices Architecture(MSA) (0) 2019.08.30