File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Garbage collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Garbage collector" Watch "Garbage collector" New topic
Author

Garbage collector

ParagS Kulkarni
Ranch Hand

Joined: Oct 04, 2004
Posts: 60
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?


Thanks, Parag
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nikhil Menon
Ranch Hand

Joined: Nov 22, 2004
Posts: 70
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

Joined: Dec 02, 2004
Posts: 9
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();


<a href="http://www.utdallas.edu/~mgo031000/" target="_blank" rel="nofollow">Marian</a>
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

....which in no way implies that the Garbage Collector will actually run.
[ December 02, 2004: Message edited by: Paul Sturrock ]
Magnus Palm�r
Greenhorn

Joined: Nov 23, 2004
Posts: 7
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.
 
Consider Paul's rocket mass heater.
 
subject: Garbage collector
 
Similar Threads
garbage collection
Finalize and System.gc()
java weakness
Forcing Full GC
Release of objects