This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!