Originally posted by Hasitha Randika:
class A{
Short s = 5;
A go(A cb){
cb = null;
return cb;
}
public static void main(String ar[]){
A c1 =new A();
A c2 =new A();
A c3 =c1.go(c2);//line 1
c1 = null;
//do stuff how many objects are eligable for the GC
}
}
what will happen when line 1 execute
Originally posted by Ratnankur Kushary:
Why dont you install eclipse in your PC and compile the program and try to interprete the error??
Originally posted by Ahmed Yehia:
This code doesnt give any error, its about Garbage collection
when line 1 execute, you are setting reference variable 'c3' to null as a result of invoking go().
In your program only object 'c1' is eligible for GC
what will happen when line 1 execute
Why dont you install eclipse in your PC and compile the program and try to interprete the error?
all events occur in real time
Originally posted by Burkhard Hassel:
The first object is eligible, the second is still referred by c2.
With the first object eligible, also the X-object (A has a X) is eligible, so totally two. This would be not the case if A had a Short.
Yours,
Bu.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Originally posted by Sarah Jorden:
here when object c1 is eligible for garbage collection, the object x associated with object c1 will not be eligible for garbage collection, right?
here when object c1 is eligible for garbage collection, the object x associated with object c1 will not be eligible for garbage collection, right?
because object X is still being referred by reference variable x. but yes, it won't be accessible since c1 object is now null.
So, ultimately only one object c1 will be eligible for garbage collection.
Correct me please if I'm going wrong.
all events occur in real time
So whenever we want to know 'How many objects are eligible for Garbage Collection?' we can use System.gc() and finalize(), right?
or are there any cases when we can't actually know?
all events occur in real time
Don't get me started about those stupid light bulbs. |