Here is my 2 cents worth.
(a) Simply put, all Java Objects are allocated memory in Heap.
(b) Primitives types (not *array* of primitives) and references to objects are allocated on the stack.
(c) Importantly, each thread in the JVM gets it own stack and the VM option
-Xss decides the stack size for each thread.
Note: If the stack size is too small, eventually you see "StackOverflowError".
Example:class FooBar{ public void get(MyTest obj) // obj a reference to an object - stack.
{ int x = 10; // Stack
Vector tmpObj=new Vector(); // Heap
...
...
}
}
Note: tmpObj will be garbage collection based on the rules
(like reference count and others) that GC maintains to check its life span.
HTH.