简体   繁体   English

调用System.gc()是否会重置统计数据以进行世代收集?

[英]Does calling System.gc() reset the statistical data for generational collection?

In other words: 换一种说法:

I need to know if after calling System.gc() object instances (that are not collected) are distributed between generations in the same way as before calling System.gc() . 我需要知道在调用System.gc()对象实例(未收集)是否以与调用System.gc()之前相同的方式分布在各代之间。

Thanks, 谢谢,

After a Full GC, which a System.gc() may or may not trigger, 在完成GC之后,System.gc()可能会触发也可能不会触发,

  • the Eden space will be empty, so anything in there will be moved out or cleaned up. 伊甸园空间将是空的,因此其中的任何东西都将被移走或清理。
  • the Survivor spaces will swap objects from the one which has objects to the empty one, and 幸存者空间会将对象从具有对象的对象交换为空的对象,然后
  • the Tenured space will have the same retained objects it had before but some may have been cleaned up and some may be new to that generation. 保有权空间将具有与以前相同的保留对象,但其中一些可能已被清理,而某些可能是这一代的新对象。

In short, the only time System.gc() won't change objects between generations is when 简而言之,System.gc()不会在各代之间更改对象的唯一时间是何时

  • it doesn't do anything because it is ignored 它什么也不做,因为它被忽略了
  • no objects have been created or discarded since the last Full GC. 自上次Full GC以来,没有创建或丢弃任何对象。

if this could be another reason why calling System.gc() is evil 如果这可能是调用System.gc()是邪恶的另一个原因

Mostly because it hurts performance and you gain very little in return. 主要是因为它损害了性能,您获得的回报却很小。 Note: the RMI can trigger a full collection periodically to ensure distributed objects are cleaned up but it tries to keep this to a minimum. 注意:RMI可以定期触发完整的收集,以确保清除分布式对象,但是它试图将其保持在最低水平。

First of all, System.gc() is only a hint to the JVM that you want a GC, it might not trigger one (if using -XX:+DisableExplicitGC with Hotspot for example), and you should not rely on it doing anything -- the JVM usually knows better anyway. 首先, System.gc()只是向JVM提示您想要GC,它可能不会触发(例如,如果将-XX:+DisableExplicitGC与Hotspot一起使用),则您不应依赖它执行任何操作-JVM通常反而是更好。

If it does trigger a GC, then it's just like any other GC, and objects might get promoted from the young to the old generation if they satisfy the criteria (enough generations spent in the survivor spaces for example). 如果它确实触发了GC,则它与任何其他GC一样,如果满足条件(例如,足够的世代在幸存者空间中使用),则对象可能会从年轻一代升级为老一代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM