• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collection

 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#3 At what point will the object created on line 8 be eligible for garbage collection?

1 public class RJMould{
2 StringBuffer sb;
3 public static void main(String argv[]){
4 RJMould rjm = new RJMould();
5 rjm.kansas();
6 }
7 public void kansas(){
8 sb = new StringBuffer("Manchester");
9 StringBuffer sb2 = sb;
10 StringBuffer sb3 = new StringBuffer("Chester");
11 sb=sb3;
12 sb3=null;
13 sb2=null;
14 }
15 }



1 Line 11
2 Line 9
3 Line 12
4 Line 13
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
12 ??
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think the answer is?

Also, please QuoteYourSources.
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think ans is 12.
because sb refers to sb3, so it means when sb3 eligible for gc then sb will be eligible for gc as well.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
13?
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yes it should be 13 Ankur...
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
curve karve wrote:#3 At what point will the object created on line 8 be eligible for garbage collection?

1 public class RJMould{
2 StringBuffer sb;
3 public static void main(String argv[]){
4 RJMould rjm = new RJMould();
5 rjm.kansas();
6 }
7 public void kansas(){
8 sb = new StringBuffer("Manchester");
9 StringBuffer sb2 = sb;
10 StringBuffer sb3 = new StringBuffer("Chester");
11 sb=sb3;
12 sb3=null;
13 sb2=null;
14 }
15 }



1 Line 11
2 Line 9
3 Line 12
4 Line 13


Answer:
4

Explanation:
On line 9 the object created on line 8 has the reference sb2 pointed to it. Until something happens to make that reference unable to reach the object it will not be eligible for garbage collection...............

 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good questions on gc...where are the questions from?
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got encountered to one of SCJP free mock tests online..from there..i am getting screwed badly....
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tomoro is my exam....you prepared me for gc
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how are you prep for exam???good luck
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
follow K&B...the king of kings
 
Phungsuk Wangdu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good question answer 4 must be right
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic