I am having an issue with slow garbage collection. Obviously, the more objects in heap (all else equal) will lead to longer GC time, and larger sized objects in heap will lead to longer GC times.
However I am wondering about the trade-off between object size and number of objects. For example, comparing two sets of objects that are the same total megabytes but one set has 1,000,000 objects and the other has 5 objects, which is faster to GC?
It is related to number of objects and complexity and number of references. Basically, how long it takes to visit and mark everything that is "reachable".
This is because it does a mark and sweep where it will move from root(s) to tips and mark everything that can be reached. Everything else is just marked as free memory, regardless of size.
Overall GC Performance
As mentioned in the comments by @Nick Holt, Garbage Collection would occur more frequently with larger objects as they would fill the heap faster affecting GC performance. Clearing out a 100Gig object should still be faster than clearing out 100Gig of 10Meg objects however.
Object size matters very little for GC performance, whereas object count matters a lot. Therefore you can expect better performance for larger objects, given a fixed memory footprint of those objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With