• 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: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

after line 6 runs,how many objects r eligible for garbage collection?
1.public class X{
2.public static void main(String args[]){
3.X x=new X();
4.X x2=m1(x);
5.X x4=new X();
6.x2=x4;
7.doComplexStuff();
8.}
9.static X m1(X mx){
10.mx=new X();
11.return mx;
12.}
13.}
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Suhita Reddy:
Hi all,

after line 6 runs,how many objects r eligible for garbage collection?
1.public class X{
2.public static void main(String args[]){
3.X x=new X();
4.X x2=m1(x);
5.X x4=new X();
6.x2=x4;
7.doComplexStuff();
8.}
9.static X m1(X mx){
10.mx=new X();
11.return mx;
12.}
13.}



Only one and it is object created by m1 method (line 4)
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed. If you assume that the System.gc() calls work as expected in the following code - you can see it happen:

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding the above test: run it at the command line rather than using an IDE.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic