Course notes taken for CSCB07/CSC207 at UofT (Software Design).
More topics on Java memory model.
- Values exist only within the function scope.
- Once returns, values are freed automatically.
- Only primitives.
- Helps stack to be small, and individual stack frames small. (so we can do recursive calls :)).
- For objects, only references (which are primitives) are passed around on stack.
- Can’t be shared between threads.
Java does not specify how references are implemented, but in C, they are integers.
- Each function have their own stack frame.
- Stack frames are destroyed once method returns.
- Objects are on the heap, they are created using
- Only destroyed if garbage collector collects it.
- Object with all its instance members (variables/methods) are put on the heap.
- Can be shared by multiple threads.
- The heap is divided into two parts:
Object Heap Spacewhere all instances live.
Static Heap Spacewhere all static members live.