File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection....." Watch "Garbage Collection....." New topic

Garbage Collection.....

G Nadeem
Ranch Hand

Joined: Apr 25, 2003
Posts: 48
this may b primitive but .....plz help.
1. public void whereEligible(){
2. Object v = new Object();
3. Object b;
4. v = null;
5. b = v;
6. }
does the variable become elligible immediatly after line 4 because of being nullified OR does it not because of active reference at line 5?
Lawrence Chettiar
Ranch Hand

Joined: Apr 10, 2003
Posts: 62
Well Nadeem,
The object which was referenced by variable v is eligible for garbage collection after line 4, what you are using at line 5 is the reference variable and not the object referenced at line 2.
Hope this makes things clear.

SCJP 1.4 (86%)<br />SCMAD Beta (77%)<br />SCEA (part I:89%,partII:93%)<br />MCAD (cleared 70-315 & 70-320 [Score 980])
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1090
Hi Nadeem
does the variable become elligible immediatly after line 4

Vairables are not garbage collected its the Object they are refering is collected. So object reffered by v may be garbage collected and not v itself.
[ June 04, 2003: Message edited by: Anupam Sinha ]
I agree. Here's the link:
subject: Garbage Collection.....
It's not a secret anymore!