Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collector decreases available memory

 
S Lei
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
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
Pie
Posts: 15367
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
S Lei
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic