• Post Reply Bookmark Topic Watch Topic
  • New Topic

HOw to Force GC

 
Ipsita Naravane
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in a situation, where because Garbage COllection has not run there is a memory problem. Once Garbage COllection runs, the problem goes away. Is there a way to increase priority on that thread or to somehow specify when to run it?
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cant really force it, but you can tell the JVM to try it's best using this command:
System.gc();
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am in a situation, where because Garbage COllection has not run there is a memory problem.

Try increasing your JVM heap size.

Is there a way to increase priority on that thread or to somehow specify when to run it?

You increase priority by invoking setPriority() but the scheduler (which is JVM-implementation-dependent) has the final say.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What sort of problem are you experiencing? Do you actually get an OutOfMemoryError? Normally GC will run before this happens, so if chances are good that the problem is that it's runing, but is not able to free any memory. Try running with the -verbose:gc option, and see what messages are printed out. That often gives a good idea what's really happening.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!