0

Is it granted that all garbage will be collected with options -Xgc:deterministic and very big-XpauseTarget=5000.

I not so much care about performance, I need to be sure that each garbage object is collected.

michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
  • `I need to be sure that each garbage object is collected` to do that you need to perform a Full GC. Possibly more than once if they override finalize(). – Peter Lawrey Oct 30 '12 at 14:35
  • @PeterLawrey, are there any way except `System.gc()` to perform full fc? – michael nesterenko Oct 30 '12 at 15:09
  • You can trigger it externally with `jmap -histo:live` or `jvisualvm` – Peter Lawrey Oct 30 '12 at 15:19
  • If it matters if an unreachable object is actually collected, your code is broken. –  Oct 30 '12 at 15:25
  • @delnan, why? I need to know if object is reachable. I have not found any easier way than forcing garbage collection. I am checking object reachability with `PhantomReference` and if its contents are null, then I can definitely say that object is unreachable. – michael nesterenko Oct 30 '12 at 16:48
  • @mishanesterenko Because it ought not matter. What may matter is if an object is still reachable (we agree on this); whether it is actually reclaimed (and when) is an implementation detail and that's a good thing(tm). If you want to check whether there is a memory leak (keeping objects alive unnecessarily), build a benchmark -- it has other applications too, and does not require you to muck with fragile implementation-specific hacks. –  Oct 30 '12 at 16:58

1 Answers1

1

This is what it says in the documentation:

The garbage collector is optimized for very short and deterministic pause times.The garbage collector will aim on keeping the garbage collection pauses below a given pause target. How well it will succeed depends on the application and the hardware. For example, a pause target on 30 ms has been verified on an application with 1 GB heap and an average of 30% live data or less at collection time, running on the following hardware:

  1. 2 x Intel Xeon 3.6 GHz, 2 MB level 2 cache, 4 GB RAM
  2. 4 x Intel Xeon 2.0 GHz, 0.5 MB level 2 cache, 8 GB RAM

Also you may want to limit the GC threads by using:

-XXgcthreads:<# threads>

Where number of threads should be 1 thread for each server core.

Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • `How well it will succeed depends on the application and the hardware` so you say that only timing is issue? And if I have really big pause time (lets say several minutes, hours etc) it will collect everything? – michael nesterenko Oct 30 '12 at 16:49
  • @mishanesterenko: I don't think several minutes are required. As you can see, it has performed well with 30ms itself with the given configuration. Pause time of few seconds should be fine, provided you have working hardware. – Yogendra Singh Oct 30 '12 at 16:56