java - Why are object stored in Heap -
why objects stored in heap?
as per understanding, object gets stored in heap , reference variable holds address of object.
reference variable stored in stack. if reference variable deleted object becomes unreachable. theoretically, object dead. (ofcourse, when there 1 reference variable referencing object).
so confusion did make necessary store object in heap ?
you mean in java, right?
- stack slice's life cycle during function call,
- stack store types has fix size, e.g interger, pointer,
- stack small,
- stack visible thread, not suitable global variables,
by way, jvm base on os, typically, on unix-like system, there stack & heap & mmap, jvm implementation make use of underling os interface, , memory model of jvm kind of similar os in aspect.
Comments
Post a Comment