This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC

 
josephine chen
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Tester extends Applet {
int a = 3;
String b = "fred";
String c = b;
Object d = new Object();
public void init() {
methodA(b);
methodB(d);
a = 5;
}
void methodA(String b) {
b = c;
c = null;
}
void methodB( Object o) {
d = new Object();
}
}
How many objects are available for GC when init() has completed?
a.0
b.1
c.2
d.3
e.4
 
gunjan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer 1.
After
void methodB( Object o) {
d = new Object();
}
is executed, the object created by
Object d = new Object();
has no reference to it and hence is available for GC
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic