Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Memory Leak Garbage Collection

 
phillip nash
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

I've got a program that obtains information from various sensors. It works fine, but I'm paranoid about the garbage collection not kicking in later on in the future.
Using VisualVm, I've noticed that every time it gets a sample of the heap, a few bytes keep on being allocating. I cannot see when the GC will kick-in to free up memory.
Because I've this I decided to code this simple program and observe the contents of the heap:



Here are my results:



As you can see, the memory usage keeps on increasing (only a few bytes).
I'm thinking if this is to do when the thread it sleeping and being woken up. The few bytes is the overhead of this (I could be wrong)

Does the GC kick in when the memory usage exceeds a certain threshold.

Thanks for your time and help.
 
Winston Gutkowski
Bartender
Pie
Posts: 10498
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
phillip nash wrote:Does the GC kick in when the memory usage exceeds a certain threshold.

I'm no great expert on this, but that's my understanding (and thresholds can be controlled by parameters to the java command).

Garbage collection is a relatively expensive activity, so you really only want it occurring when it's needed.

Winston
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last time I played with this I game to the conclusion the leak i was measuring was visual VM i.e the RMI conversation between the two.

When GC kicks in depends on what GC you have selected if your attached to the process you should be able to force GC. I suspect you have the default collector and I would expect your saw tooth graph to rise to a point and then drop all the way down and start all over.

Try turning on gc logging then get hold of a visualiser for it like gcviewer if you get a nice straight blue line forget about it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic