Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collector

 
ParagS Kulkarni
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • 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
 
Marian Olteanu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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 ]
 
Magnus Palm�r
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic