Java GC开销:如果您有10MB或10GB的*引用*对象,这有什么关系? [英] Java GCs overhead: Does it matter if you have 10mb or 10gb of *referenced* objects?

查看:108
本文介绍了Java GC开销:如果您有10MB或10GB的*引用*对象,这有什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GC必须检查并找出可以收集哪些物体。我的问题是,是否有太多的对象被检查可能会导致GC开销,或者GC有足够的智能来避免遍历所有对象以找出哪一个不再被引用?

解决方案

是的,它对标记和清除收集器您拥有多少个对象。至于这些对象的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆