wood burning stoves*
The moose likes Performance and the fly likes Memory Leak Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Memory Leak Garbage Collection" Watch "Memory Leak Garbage Collection" New topic
Author

Memory Leak Garbage Collection

phillip nash
Greenhorn

Joined: Feb 08, 2011
Posts: 21
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

Joined: Mar 17, 2011
Posts: 7700
    
  20

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 416
    
    2

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.


"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Memory Leak Garbage Collection