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 GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC" Watch "GC" New topic


Ramakrishnan Ponmudi
Ranch Hand

Joined: Apr 20, 2004
Posts: 72
myclass a = new myclass();
myclass b;
b = a;
a = null;
which object (a,b) is first garbage collected.
Rajeshwari Natarajan
Ranch Hand

Joined: Mar 05, 2003
Posts: 67
No object is garbage collected.
First off, there is only one object created at line 1.
Both the variables a and b refer to the same object. When u set a to null, b still refers to the object.
So the object can't be GC-ed.

regards<br />Rajeshwari. N
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
and even if there were 2 objects you still could not tell whether any were being garbage collected and if both then in which order.
All you can do is suggest the JVM that now would be a good time to run the garbage collector, you cannot tell the GC what to do.

I agree. Here's the link:
subject: GC
It's not a secret anymore!