Every object you create uses memory. This topic explains where Java keeps variables and objects, how memory is requested while a program runs, and how the garbage collector frees it again.
Key words in this topic
- Stack: memory for method calls; each call gets a frame that holds its local variables.
- Heap: memory for objects created with
new. - Reference: a value that tells Java where an object is on the heap.
- Garbage collector: the part of the JVM that frees objects that can no longer be reached.
- Memory leak: memory that is never freed because the program still holds on to it, or has lost the only way to free it.