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 Collector (Objects / Threads) 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 "Garbage Collector (Objects / Threads)" Watch "Garbage Collector (Objects / Threads)" New topic

Garbage Collector (Objects / Threads)

Mahesh Bansal
Ranch Hand

Joined: Nov 28, 2000
Posts: 82
I am bit confused whether objects are garbage collected or variables also. Refer Khalid Mughal page 252
void wellbehavedClasss
void wellbehavedMethod() {
File aFile;
long[] bigarray = new long[20000];
afile = null; // 1
bigArray = null //2
book say 2 objects will be ready for garbage collection
but it say that objects created using new operator are monitered by automatic garbage collector method.
Please explain.
James Baud
Ranch Hand

Joined: Jan 06, 2001
Posts: 60
aFile and bigArray are simply variables that denote references to objects. After (1) & (2) and before any other intensive activity, the objects that these variables are denoting/referencing will be eligible for garbage collection. This also means these variables are still available for other assignments, if needed.
[This message has been edited by James Baud (edited January 12, 2001).]

<B>~James Baud</B><P>He who asks, is a fool for five minutes;<BR>but, he who does not ask, remains a fool forever. (Chinese proverb)
I agree. Here's the link:
subject: Garbage Collector (Objects / Threads)
It's not a secret anymore!