SCJP 6 [SCJP - Old is Gold]
SCJP 6 [SCJP - Old is Gold]
Ram Narayan.M wrote:Static variables are allocated in Heap Memory Space...
SCJP6.0,My blog Ranchers from Delhi
Ram Narayan.M wrote:Reference Variable will also be allocated in the heap...
Amr k. Saleh wrote:
Ram Narayan.M wrote:Reference Variable will also be allocated in the heap...
if the reference variable will also be allocated in the heap , it won't be collected by garbage collector ?
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
shanky sohar wrote:By the way
Welcome to JavaRanch....Amr k. Saleh
SCJP 6 [SCJP - Old is Gold]
SCJP 6 [SCJP - Old is Gold]
Ram Narayan.M wrote:If its a static reference variables referring to objects, reference variable will also live in heap...
for instance,
class Sample {
static Integer intRef = new Integer(2);
//methods
}
Integer object gets allocated as soon as class is loaded... Since Reference variable live in heap and intRef still refers to Integer object , Object wont be eligible for GC still now... In some method, if you make intRef to refer to other object (or) intRef is nullified, that object then becomes eligible for Garbage Collection(GC).
SCJP 6 [SCJP - Old is Gold]
Amr k. Saleh wrote:
Ram Narayan.M wrote: if you make intRef to refer to other object (or) intRef is nullified, that object then becomes eligible for Garbage Collection(GC).
Sorry Ram Narayan for being picky
if i did something like this Sample.intRef = null; the intRef will be collected and no longer exists?
shanky sohar wrote:I donot know how much i am correct but i think objects live on a heap and static variable are not associated with any object.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP6.0,My blog Ranchers from Delhi
Rob Prime wrote:
shanky sohar wrote:I donot know how much i am correct but i think objects live on a heap and static variable are not associated with any object.
Actually they are associated (somehow) with an object:
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
If you go through the Java™ Language Specification and the Java™ Virtual Machine Specification, you find out the correct and definitive answer:Amr k. Saleh wrote:where do static variables live ?
Where did you find that?Amr k. Saleh wrote:Hey Guys, i've come across this
The Java Virtual Machine heap is the area of memory used by the JVM (and specifically HotSpot) for dynamic memory allocation. The heap is split up into "generations":
* The young generation stores short-lived objects that are created and immediately garbage collected.
* Objects that persist longer are moved to the old generation (also called the tenured generation).
* The permanent generation (or permgen) is used for class definitions and associated metadata.
so, maybe static variables reside in the permanent generation area
Campbell Ritchie wrote:Actually, static fields can be re-assigned (unless they are also final), so their contents would not necessarily be in the tenured or permanent generations.
SCJP6.0,My blog Ranchers from Delhi
shanky sohar wrote:
Rob Prime wrote:
shanky sohar wrote:I donot know how much i am correct but i think objects live on a heap and static variable are not associated with any object.
Actually they are associated (somehow) with an object:
DisAgree.
Because if they are associated with an object (as you say somehow).then why not statics get serialized.As it is said we can get the value of static variable only if we do the deserilization on the same JVM.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP6.0,My blog Ranchers from Delhi
Campbell Ritchie wrote:Welcome to the Ranch
SCJP6 - Java Instructor - Sun Microsystems Philippines