views:

100

answers:

1

Hello All...

Whenever a class is loaded, what are stored in the heap and what are stored in the stack ?

Also where does the threads reside ?

Thanks in advance...

+3  A: 

Reference types are in heap.

Any primitive type data and references to values on heap (parameters / local variables of method) are on the stack.

Each thread has its own stack.

All threads in the application share same heap.

MasterGaurav
@Nirmal: It's nothing strange. It's the same behaviour across all runtimes be it C/C++ runtime or otherwise. So, I don't really understand "why" the "why" from your side :)
MasterGaurav
"Any primitive type data... are on the heap" is a little confusing. The heap does store primitives if they are data members of objects.
Eyal Schneider
Yes. It does.. but then, as you mentioned, as part of Composites.However, the moment we access the data, it's first copied on to the stack. For example, for an Object with definition ComplexNumber { float real, float imaginary }, in a method doWork(ComplexNumber cn} { return cn.real * cn.real + float.imaginary * float.imaginary; }the values real/imaginary are first brought onto the stack unline cn where only the reference is brought onto the stack
MasterGaurav
Grrr! I wish, there was formatting for comments.!
MasterGaurav