• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about gc() and runFinalization()

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do the following codes get the same output?
1. //...
System.gc();
System.runFinalization();
}
2.//...
System.runFinalization();
System.gc();
}
"Thinking in Java" says, the different output will be shown, and code2 will never implement the finalization. But I get the same result in JDK1.1.5 environment. Why? Thanks.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.runFinalization() executes the finalize methods of any objects that have been GCed but not yet finalized. In theory, the example 2 might gc some additional objects.
The details of exactly what happens when are up to the implementation of the JVM, and the exact sequence of events prior to executing the test code.
Bill

------------------
author of:
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey bill!
i think System.runFinalization() runs the finalize method for objects which are eligible to be gced but not yet gced! please check!
 
reply
    Bookmark Topic Watch Topic
  • New Topic