This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collector (Objects / Threads)

 
Mahesh Bansal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am bit confused whether objects are garbage collected or variables also. Refer Khalid Mughal page 252
import java.io.*;
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.
Mahesh
 
James Baud
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic