• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DELETED
 
I child proofed my house but they still get in. Distract them with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic