wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes on STACK or on HEAP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "on STACK or on HEAP?" Watch "on STACK or on HEAP?" New topic
Author

on STACK or on HEAP?

Soma RaviKumar
Greenhorn

Joined: Jan 03, 2006
Posts: 6
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

Joined: Sep 16, 2005
Posts: 1780
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.


There is no emoticon for what I am feeling!
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
This thread might give you an answer.


ASCII silly question, Get a silly ANSI.
badri nath
Ranch Hand

Joined: Dec 21, 2005
Posts: 57
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

Joined: Sep 16, 2005
Posts: 1780
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

Joined: Oct 07, 2005
Posts: 637
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.
 
Don't get me started about those stupid light bulbs.
 
subject: on STACK or on HEAP?