-
Notifications
You must be signed in to change notification settings - Fork 3
Java Memory Model
kgleong edited this page Sep 9, 2015
·
2 revisions
- References
The JVM divides memory between thread stacks and the heap.
What is a thread stack?
- each thread has its own stack that consists of the following:
- local variables
- references to objects or the primitive data itself
- each method on the call stack for that thread
- local variables
- local primitive variables on the stack are only visible to the thread that owns it.
- local reference variables that point to objects on the heap are also only visible to the owning thread.
What is the heap?
- The heap contains all objects created by the application.
- Objects reside here regardless of which thread created them.
- Primitive member variables are stored on the heap, while local primitives are stored on the thread stack.
- Objects on the heap are visible to all threads.