Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visual vm force gc

  1. i sampling the memory usage and count number of instances for POJO. if when i press 'garbage collecting' in visual vm and i can see the instances down , does that mean it's memory leak free ?

  2. how to force jvm do garbage collecting everyday at midgnight ? (just like automatically press garbage collect on visualvm) ? i see visualvm 's cpu usage, gc is always 0%. i set -xmx -xms 1024m, but normally memory usage around 200mb. is this because GC is only done when necessary? that's why always 0% for gc cpu time

  3. how to check the time of last time doing 'full GC' ?

like image 265
cometta Avatar asked May 18 '26 04:05

cometta


1 Answers

  1. No, not necessarily. All that really means is that some of your objects can be collected. You could still have a garbage leak if, for example, the instance count always went down after a GC but not quite to the same level as before; if this "baseline" increased over time you'd run out of memory occasionally. Also, it's very hard to prove a negative, so it could be that your application does have a memory leak bug, but this specific situation isn't exercising it.
  2. Let's clarify one thing - you can never force the JVM to run garbage collection. The best you can do is call System.gc(), which is a hint to the JVM that it might want to run GC now. It doesn't have to do anything, and a no-op implementation of that method would be perfectly valid. Basically, garbage collection "just happens" and the less you place specific expectations on it the better. So basically, yes, it will typically only run when needed.
  3. Again, this is typically internal knowledge and the details will depend on which garbage collector implementation you're using. For Sun's JVM, however, you can use the command-line argument -verbose:gc to get verbose garbage collection details output to the console. If you want to inspect the details programmatically or visually, this information might be exposed via JMX too (i.e. set up your process to use JMX remoting, and connect to it with JConsole). For me, using Sun's 1.5.0_06 JVM, I see an MBean in java.lang.GarbageCollector that exposes some information including the time of the last full GC.
like image 113
Andrzej Doyle Avatar answered May 19 '26 16:05

Andrzej Doyle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!