aspose file tools*
The moose likes Java in General and the fly likes when System.gc cannot gaurantee that garbage collection would  be run then what is it used for? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "when System.gc cannot gaurantee that garbage collection would  be run then what is it used for?" Watch "when System.gc cannot gaurantee that garbage collection would  be run then what is it used for?" New topic
Author

when System.gc cannot gaurantee that garbage collection would be run then what is it used for?

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 644
I read that System.gc cannot gaurantee that garbage collection would be run. If is it so then why would anyone use System.gc?

thanks
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2317
    
  49
The simple answer is you shouldn't ever need to call gc() - although it probably won't make much difference if you do as it only gives a suggestion to the garbage collector that it may want to run.

It may have been that in the early days of Java this had some useful function (I really can't remember) but certainly these days the garbage collector(s) are much better at knowing when to run than you are. They also have less of a performance hit than they used to so you don't notice them running so much - I do remember occasions in the early days when you would get noticeable pauses when a garbage collection cycle ran. I guess improvement to garbage collection algorithms, general performance improvements and massive increases in raw computing power have sorted that out.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Personally, I have run System.gc() right after generating some complex display that I knew the user will take some time to evaluate.

As Tony said, this was more significant with earlier versions of Java where GC was slower and we were running on slower processors.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when System.gc cannot gaurantee that garbage collection would be run then what is it used for?