• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Memory Leak Garbage Collection

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic