Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

on STACK or on HEAP?

 
Soma RaviKumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I know that the objects are created on HEAP and so I believe that the references to it reside on STACK.

Is an array created on STACK or on HEAP ? In other words, does it behave like a primitive variable (which is created on STACK) or like an object (Which is created on HEAP or in between? If it is in between, what is on STACK and what is on HEAP?

Thanks in advance
Ravi
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects reside in the heap. Arrays are objects. References may be on the stack or in the heap: local variables are on the stack, fields on the heap.
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread might give you an answer.
 
badri nath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heap contains the objects where as stacks contain every reference of all objects that are in heap except for primitive datatypes
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by badrinath ch:
Heap contains the objects where as stacks contain every reference of all objects that are in heap except for primitive datatypes

That's false. See my previous example. The field reference b is in the heap because it is part of an object. Only parameters and local references are in stack frames.
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Albrechtsen:

That's false. See my previous example. The field reference b is in the heap because it is part of an object. Only parameters and local references are in stack frames.


We went thru this whole discussion in the another thread alluded to above. Reading that thread should clarify matters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic