• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

doubt regarding a question abt garbage collections K&B 3rd chapter  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the following class; and my doubt is at line 3 how many obj are eligible for garbage collection. The answer is 2( q1 and story) .But at line 1 when q3 =null, means it is also eligible for garbage collection right? Can anyone please help me understand this in a more detailed way.

public class Ques04 {
Short story = 200;
Ques04 Ques04(Ques04 q) {
q = null;
return q;
}
public static void main(String[] args) {
Ques04 q1 = new Ques04();
Ques04 q2 = new Ques04();
Ques04 q3 = q1.Ques04(q2);//line 1
System.out.println(q3);//line 2
q1 = null;//line 3
}
}
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sree,

Please quote your sources. We won't be able to help you until you do so.

Thanks.
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sree javab wrote:Hi,
I have the following class; and my doubt is at line 3 how many obj are eligible for garbage collection. The answer is 2( q1 and story) .But at line 1 when q3 =null, means it is also eligible for garbage collection right? Can anyone please help me understand this in a more detailed way.

public class Ques04 {
Short story = 200;
Ques04 Ques04(Ques04 q) {
q = null;
return q;
}
public static void main(String[] args) {
Ques04 q1 = new Ques04();
Ques04 q2 = new Ques04();
Ques04 q3 = q1.Ques04(q2);//line 1
System.out.println(q3);//line 2
q1 = null;//line 3
}
}



q3 is an object reference, not an object, so if it is set to null it doesn't mean there is another object available for the dreaded GC.
 
sree javab
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe, that clarifies my doubt.

Ruben,
I mentioned that my question was from Kathy and BertBates 3rd chapter in the subject line itself. Please look at the subject of the post.

Thanks.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you sure did Sree. I don't know how I missed that...
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DELETED
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!