aspose file tools*
The moose likes Beginning Java and the fly likes When will a variable use memory from stack and when will use memory from heap? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "When will a variable use memory from stack and when will use memory from heap? " Watch "When will a variable use memory from stack and when will use memory from heap? " New topic
Author

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

Mr Chan
Greenhorn

Joined: Jun 08, 2002
Posts: 2
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
Static variables use memory from stack while instance variables use memory from heap.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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
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: 9046
    
  10
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
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

Joined: Jul 11, 2001
Posts: 14112
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When will a variable use memory from stack and when will use memory from heap?