Java GC开销:如果您有10MB或10GB的*引用*对象,这有什么关系? [英] Java GCs overhead: Does it matter if you have 10mb or 10gb of *referenced* objects?
问题描述
是的,它对标记和清除收集器您拥有多少个对象。至于这些对象的 size ,这可能也很重要:如果需要压缩10GB的东西而不是10MB的东西,压缩收集器需要做更多的工作。
说到这一点,现代垃圾收集器非常复杂(它们在多个堆上操作,在后台执行操作,可以使用多个内核等)。他们也是高度可配置的。此外,一个典型的JVM配备了多个垃圾收集器。
因此很难对这样的一般问题给出有意义的,精确的答案。 b
The GC has to check and find out which objects can be collected. My question is whether having too many objects to be checked can cause a GC overhead or somehow the GC is smart enough to avoid having to iterate through all the objects to find out which one is not referenced anymore?
Yes, it does matter to the mark-and-sweep collector how many objects you have. As to the size of those objects, that could matter too: a compacting collector would have more work to do if it needed to compact 10GB worth of stuff rather than 10MB of stuff.
Having said this, modern garbage collectors are extremely sophisticated (they operate on multiple heaps, do things in the background, can use multiple cores etc). They are also highly configurable. Furthermore, a typical JVM comes equipped with multiple garbage collectors.
It is therefore hard to give meaningful, precise answers to general questions like this.
这篇关于Java GC开销:如果您有10MB或10GB的*引用*对象,这有什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!