• 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

Garbage collector

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why cant we force garbage collector to execute? Why Java creators have left it upto the scheduler to execute when to execute garbage collector thread?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Why Java creators have left it upto the scheduler to execute when to execute garbage collector thread?


Its probably based on the assumption that your average developer will not know nearly enough to do GC efficiently. Its also one of the basic aims of Java that the programmer should be shielded form such low-level (and quite often error prone) tasks so they can concentrate of the actually business problem, rather then the internal machinations of a processes environment.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Its probably based on the assumption that your average developer will not know nearly enough to do GC efficiently



Well as i have learned thats not the prominent reason behind not giving the programmer a chance to force the GC run.

The reason for Sun to leave it at the mercy of JVM is...
(1) GC in Java 1.1 was a seperate thread with a higher priority and so it will run with fairly even manner with the main thread etc. This deterioted the program efficiency as it became a overhead for the scheduler to run GC everytime. The Garbage Collection cycle is still a very expensive operation.

(2) So from later versions onwards they made the GC thread with a lower priority. And it assures that there is no overhead on the JVM in managing an extra cycle(instruction/machine cycle) for the operation og GC alway. It may run or never run. But it is most probable to run whenever the memory is packed to almost full and to an extend it would avoid OutOfMemoryException.

Being a Java programmer you are given an advantage of getting insulated from the CPU related system level operations. So leave that work load to whoever concerned(JVM or OS).

Nikhil Kanjulli Menon
SCJP 1.4
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Parag S. Kulkarni:
Why cant we force garbage collector to execute? Why Java creators have left it upto the scheduler to execute when to execute garbage collector thread?



You can: System.gc();
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
....which in no way implies that the Garbage Collector will actually run.
[ December 02, 2004: Message edited by: Paul Sturrock ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could check out this link for more information regarding tuning garbage collection:
Performance Documentation for the Java HotSpot VM

Where you will find links to tuning gc the latest hotspot jvms.
 
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic