Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I force Garbage Collection to run on a java process? 1

Status
Not open for further replies.

cpjust

Programmer
Sep 23, 2003
2,132
US
Hi,
I'm wondering if there's a way to force the garbage collector to run on a running java process (like Eclipse)?

I know how to run System.gc() in my own code, but I want to run it on a process that's already running, because programs like Eclipse start eating up a lot of memory if you leave them running for several weeks...
 
For the Eclipse case, there's and option under Window > Preferences > General > Show heap status that will display on the lower rith corner how much memory is used and a button to force GC.

For other cases, I'd consider changing the GC algorithm rather than forcing it from time to time.

Cheers,
Dian
 
Thanks, that's perfect!
I'm not sure what you mean about changing the GC algorithm though? Do you mean changing the applications source code, or just changing the java command line options?

What I was originally thinking of doing is creating a cron job to run the GC (somehow) on all my java processes at night when I'm not at work.
 
Well, those are two differente fields:

- Of course, if you have control over the source code, you have to purge possible memory problems by unreferencing unused objects

- Appart from that, you can do some performance tuning and choose the better GC algorithm for your app and specify it from command line

IMHO, by scheduling a GC, you're hiding the problem behind the carpet

Cheers,
Dian
 
I always thought you couldnt force GC, just request it to be run? (ie may not be run....)
 
Well, if you push it hard enough, say 10 times in a loop, it will run, nearly instantly, but if you that too often, then performance will degrade.
 
Well, Dian, not if you have a custom middleware (usually running Cobol applications) with a minimalistic Java runtime piggy-backed on top of it, taking only a few MB, where a standard load of the JRE per middleware instance (several hundreds per server) would take around 48 MB at least (JRE 1.4 last measured, probably more on JRE 6). Downside is that the automatic GC is not started in our environment... :-( And yes, we are fading this middleware out, but as you probably know about Cobol, it's quite hard to kill it, so it will take a few more years to get rid of it ;-)
 
Use the JVM command line options to limit the memory and to set the GC strategy. Why would you want to call the GC programmatically?

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top