This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Garbage collection  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we invoke gc explicitly in a mock exam question it is found that set reference to null and reassigning it to another object there is a chance of getting garbage collected codei s like this
cosider this is in main method
1)Strin s1 = "aaa";
2)Strin s2 = "bbb";
3)Object a = s1;
4)a = null;
5)a = b;
Quetion is where is object a likely to get garbage collected line numbers is given as choice
Please clarify
Rk Raj
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)Strin s1 = "aaa";
2)Strin s2 = "bbb";
3)Object a = s1;
4)a = null;
5)a = b;
Here variable is available for garbage collection just before line no:5 or to put in another way, after the execution of line no:4.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Balaji:
Here variable is available for garbage collection...
a small correction...
What you seem to say is correct, however
the variable is not the one which is being GC. The object
referenced by the variable
is being GC, since it has no
further references.
Regds.
- satya
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here should be small corection it should be String //Strin
U dont b for which it is refering // not clear for b;
String a="skldjf";
String s2 ="adfkl";
Object a=s1;
a=null; //if u say a to null still s1 is referring to that string object
no garbage collection.
i hope it is clear.
suresh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!