• 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

garbage collection

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,




here i am not getting as to what is e3.e.i understand that e3 is a
reference pointing to an Eco object and e is also a reference
so how to interpret e3.e and please explain as to how many object
are eligible for garbage collection my answer is 2 objects are
eligible.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Eco {
public static void main(String[] args) {
Eco e1 = new Eco();
Eco e2 = new Eco();
Eco e3 = new Eco();
e3.e = e2;
e1.e = e3;
e2 = null;//line1
e3 = null;
e2.e = e1;//line3
e1 = null;
}
Eco e;//line 5
}




This program will have a Nullpointer Exception created because at Line 1 you are assigning "null" to e2 and after that at Line 3 you are using the dot operator on a null reference.So This creates a null Pointer Exception.

In Line 5:
Here 'e' is an instance variable of class Eco.So all the objects that you create for Class Eco will have 'e' in it.
[ October 22, 2007: Message edited by: Thirumalai Muthu ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic