For Programmers: Free Programming Magazines  


Home > Archive > Java Help > August 2005 > how java variables are stored?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how java variables are stored?
rahul8143@gmail.com

2005-08-13, 10:01 pm

hello,
In java turorial i read that if code is
int arr[];
arr= new int [100];
then arr is stored on stack and actual array is stored on heap.
what this mean? why same arr variable require space in stack and heap
also?
regards,
rahul

Tor Iver Wilhelmsen

2005-08-14, 4:01 am

rahul8143@gmail.com writes:

> what this mean? why same arr variable require space in stack and heap
> also?


The reference to the array is on the stack, the actual array object is
on the heap.
Dale King

2005-08-14, 10:02 pm

Tor Iver Wilhelmsen wrote:
> rahul8143@gmail.com writes:
>
>
>
> The reference to the array is on the stack, the actual array object is
> on the heap.


But the distinction can get a little blurred with the generational
garbage collector. Objects initially are allocated in the nursery which
is basically a stack. When the nursery fills up any live objects are
moved to the heap. So short-lived objects may never make it to the heap.
--
Dale King
Mario Winterer

2005-08-18, 6:00 pm

Correct.
But: For the development of most of this worlds java applications,
you do not have to care a pap for if it is on the stack or heap - it simply works!

Tex


"Tor Iver Wilhelmsen" <jadedgamer@hotmail.com> wrote in message news:ull359ctd.fsf@hotmail.com...
> rahul8143@gmail.com writes:
>
>
> The reference to the array is on the stack, the actual array object is
> on the heap.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com