Skip to content
kgleong edited this page Sep 9, 2015 · 2 revisions

What is the Java memory model?

Java Memory Model

Java thread stack and heap memory

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 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.

stack and heap references

Computer Hardware Memory

Computer memory

The Java Memory Model and how it maps to Computer Hardware Memory

Clone this wiki locally