This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
When will a variable use memory from stack and when will use memory from heap?
Mr Chan
Greenhorn
Joined: Jun 08, 2002
Posts: 2
posted
0
When will a variable use memory from stack and when will use memory from heap?
Manoj Tyagi
Ranch Hand
Joined: Jun 11, 2002
Posts: 35
posted
0
Static variables use memory from stack while instance variables use memory from heap.
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Instance variables exist inside objects on the heap. Therefore they are also on the heap. Local variables exist only in the stack. They are not part of the structure of the object. Static variables exist in the classfile structure that is created when the class is loaded. However it is not a simple as that. Stacks hold frames (one frame per method) but the frames may be "heap allocated" so it gets sort of fuzzy. Technically the Method area may be heap allocated also (depending on who wrote the JVM). For all practical purposes though, the word "heap" is used to describe just the area that holds the objects and arrays.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Swathi Krishn
Greenhorn
Joined: Jun 11, 2002
Posts: 4
posted
0
Hi, I am new to computer field, so what do heap, stack means? Can anyone explain me. Thanks in advance.
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
Heap and stack are different areas of memory.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
raj madhuram
Ranch Hand
Joined: Oct 10, 2001
Posts: 71
posted
0
Originally posted by Swath: Hi, I am new to computer field, so what do heap, stack means? Can anyone explain me. Thanks in advance.
Originally posted by Swath: Hi, I am new to computer field, so what do heap, stack means? Can anyone explain me. Thanks in advance.
Did you try a google search?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus