• Post Reply Bookmark Topic Watch Topic
  • New Topic

JVM heap stores local objects??  RSS feed

 
Krishna Srinivasan
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java virtual machine has a heap that is shared among all Java virtual machine threads. The heap is the runtime data area from which memory for all class instances and arrays is allocated.


this means all the instances of the classes are stored in heap...
if we create an instance inside a method, will it stored in heap?bcos its local variable...

Plz... can you explain this......
 
Kris Philippaerts
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Krishna Srinivasan:


this means all the instances of the classes are stored in heap...
if we create an instance inside a method, will it stored in heap?bcos its local variable...

Plz... can you explain this......


Java uses two concepts for storing data. The heap and the stack. The stack grows and shrinks with calling methods, and can only contain local variables. Variables that are put on the stack should have a fixed size, since the stack frame should be known on beforehand by the compiler. This means that only primitive variables and references to objects can be stored on the stack. The object itself (which can have a variable size) wil always be stored on the heap. No matter from where it is instantiated.

Hope this helps,
Kris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!