Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
    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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

About Garbage Collection

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Report post to moderator
Closing thread, it is (at least) double
Bu.
 
Beware the other head of science - it bites! Nibble on this message:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic