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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

About Garbage Collection

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
code:

Class CardBoard{
Short story=5;
CardBoard go(CardBoard cd){
cd=null;
return cd;}
public static void min(String ags[]){
CardBoard c1= new CardBoard();
CardBoard c2=new CardBoard():
CardBoard c3= c1.go(c2);
c1=null;
}
}

now at the end 2 objs are eligible for gc..Can any one explain..

Thanks in advance..
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator


code:

Class CardBoard{
Short story=5;
CardBoard go(CardBoard cd){
cd=null;
return cd;}
public static void min(String ags[]){
CardBoard c1= new CardBoard();
CardBoard c2=new CardBoard():
CardBoard c3= c1.go(c2);
c1=null;
}
}



There would be only one object for Garbage collection.
While you pass c2(copy of reference)in method go() and made it null, still it's original object's reference is maintained by c2,see before line CardBoard c3= c1.go(c2);

and finally you made c1 as null so Object referred by c1 becomes eligible for garbage collection....
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing thread, it is (at least) double
Bu.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic