Why are reference types stored in heap
06:17 17 Dec 2012

I do know that in Java, (perhaps in .net too), primitives are stored in the stack, whereas reference types are stored in the heap.

I do not understand the pros/cons for this behavior. Why can't we reference a memory location inside our stacks instead? I couldn't find a proper explanation as I googled (maybe I suck at it), but if you people could provide some insights I would be grateful.

Thanks.

java jvm heap-memory