Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collection

 
Kris Decker
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to FORCE garbage collection? I have put some calls to System.gc() in my code but (as I expected) the system sees the call but keeps chugging (no garbage collection)
Any help would be greatly appreciated.
Kris
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can request the system to do a garbage collection, but there is no guarantee that it will happen. You can't force it.
Dale

------------------
By failing to prepare, you are preparing to fail.
Benjamin Franklin (1706 - 1790)
 
Kris Decker
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, then that lends the question:
How do programs such as JProbe force garbage collection when you click on the garbage collection button?
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not familiar with JProbe. But according to the JVM specs, GC can not be forced, It can only be suggested. You can ask the GC to execute, but it's up to the JVM when, and if at all, the GC runs.


------------------
Bosun
SCJP for the Java� 2 Platform
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presumably, rather like a debugger, JProbe taps into interfaces (JPDA, JVMPI ...?) that let it do stuff inside the JVM that a normal program cannot. You wouldn't want to have a normal application attempt to use such interfaces.
 
Armand Aquino
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes when you know you're done with the object, just set it to null. But still there is no guarantee that anything will force gc.
 
Dave Turner
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it that you are actually trying to achieve by running the garbage collector, there is most likely an easier and more reliable way than using the gc.
Dave
Originally posted by Kris Decker:
Is there any way to FORCE garbage collection? I have put some calls to System.gc() in my code but (as I expected) the system sees the call but keeps chugging (no garbage collection)
Any help would be greatly appreciated.
Kris

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic