• 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

GC

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic