Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!