This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When will a variable use memory from stack and when will use memory from heap?

 
Mr Chan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When will a variable use memory from stack and when will use memory from heap?
 
Manoj Tyagi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static variables use memory from stack while instance variables use memory from heap.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Swathi Krishn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to computer field, so what do heap, stack means?
Can anyone explain me.
Thanks in advance.
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heap and stack are different areas of memory.
 
raj madhuram
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Swath:
Hi,
I am new to computer field, so what do heap, stack means?
Can anyone explain me.
Thanks in advance.

http://whatis.techtarget.com/definition/0,,sid9_gci212239,00.html
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic