File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Garbage Collector decreases available memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Garbage Collector decreases available memory" Watch "Garbage Collector decreases available memory" New topic

Garbage Collector decreases available memory

S Lei

Joined: Feb 20, 2010
Posts: 7
Nearly every time I used the gc() method in the Runtime object, I was noticing, that it actually seemed to consume a few megabytes of my available memory. I used the method directly after heavy-duty image operations where I disposed all objects and nulled the database. I don't know why this happens, any ideas?

Thanks =)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

That's very hard to answer without knowing in detail what your program does.

It is almost always not necessary to call the gc() method. The garbage collector in the JVM is a sophisticated piece of software, and usually it knows better than you how and when to do garbage collection. You should never call gc() just because you have some vague feeling that it might be a good idea - trying to "help" the garbage collector might even be counter-productive, as you've discovered with your program.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
S Lei

Joined: Feb 20, 2010
Posts: 7
Mh. Yes, I think that would be the solution, to just let it do it's job . I only thought, that it might be a good idea sind I heard a speech about it long ago, in which the garbage collection jsut seemed to cleanup in regular time-periods.

Kind Regards,
Simon Leischnig
I agree. Here's the link:
subject: Garbage Collector decreases available memory
It's not a secret anymore!