Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

ask help about gc!!!

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1public class Q2 {
2 public static void main (String[] args) {
3 String s = "Hello World ";
4 String s1 = "Hello";
5 s = s1;
6 s = null;
7 s1 = null;
8 System.out.println(s);
9 }
10}
How many objects will be Garbage collected by the time execution completes Line 8?
1One
2Two
3Three
4Cannot determine
the answer is 4,I don't know why??? who can tell me?
 
AnthonyHan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will attend the exam tomorrow,who can explain it for me?Thanks a lot!!!
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not possible to determine when garbage collection will take place, only to say that a piece of unused memory has become eligible for collection.
Good Luck in the exam.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anthony,
Read the question, it says "will be garbage collected" and not "how many are eligible for garbage collection".
Good luck for ur exam, tell us how u did
Nandini
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anthony,
Just to add to Nandini's answer; there are no guarantees about when the garbage collector will run or the order in which objects eligible for collection will be collected.
If the program is very small it may exit before the gc runs at all.

Hope that helps.

------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah read the question carefull before answering it.Of course u cannot determine when will be the object will be collected by Garbage Collection but u can determine when the object is eligible for garbage collection.Yes sometimes ur program will end before any garbage collection takes place hence giving no chance to run the thread garbage collector.
For exam i will say read teh question carefully before naswering.
Good Luck
------------------
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic