• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

difference between gc and runFinalization

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

what is the difference between System.fc(); and System.runFinalization()?
and which is more preferred?

thanks in advance
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gc() suggests that the garbage collector should dispose of unused objects; runFinalization() suggests that it should run the finalize() methods of objects that are already queued for disposal.

Which one is preferred? Neither. You should never (with exceedingly few exceptions that come up only in very obscure situations in tool and platform development) call either -- period. Leave the garbage collector alone to do its work -- it knows what it's doing.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do they really? Is the GC in 1.5 better than the one in 1.4? The one in 1.4 does not know when it should collect garbage except for when the memory is low or some other object based metric. It does not seem to have a conciousness for when the user is taking a brake.

Seems like the GC is triggered by action rather than inaction. So given the opportunity, I'd call GC if I knew for sure my program was idle.
[ July 07, 2006: Message edited by: Mr. C Lamont Gilbert ]
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
calling gc does nothing (or rather is not guaranteed to do anything).
Calling it explicitly is therefore hardly ever something you should do, if and when the JVM needs memory it will find a place to do its thing.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JVM tends to find the wrong place to do its thing causing long pauses in my program. There is always the incremental GC but that slows the whole thing down noticeably even on a very fast computer. I'm still talking 1.4 here as 1.5 may be better, I don't know.

Nothing beats calling the GC when your program is idle. I highly recommend it. Knowing when its idle may be tricky, but if you do, a call to gc can only help. Its certainly not worse than having the user maximize the window to a long pause.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it gives a false sense of achievement though. You THINK you're controlling garbage collection, when in fact you're not.
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:
gc() suggests that the garbage collector should dispose of unused objects; runFinalization() suggests that it should run the finalize() methods of objects that are already queued for disposal.




so, runFinalization() suggest's that it should run finalize() methods of all the obejcts

what happens if i am not calling finalize() method ?will JVM do for me b4 GC ing ???
:roll:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!