java - 是否始终调用 gc,即使堆空间在运行时连续可用?

标签 java garbage-collection

根据 Java 平台标准版 HotSpot 虚拟机垃圾收集调优指南 标题为 "Generations" 的部分

When the young generation fills up, it causes a minor collection in which only the young generation is collected

和:

Eventually, the tenured generation will fill up and must be collected, resulting in a major collection, in which the entire heap is collected.

所以如果应用程序已经完成了分配阶段,并且 在整个应用程序的执行过程中,年轻代和老年代都没有被填充(在任何阶段都没有),那么gc甚至不会发生一次?

如果会发生,原因是什么?因为这似乎与链接的文档相反。

最佳答案

So if the application finished the allocation phase, and throughout the execution of the application, the young and tenured generations are not filled up (at all, in any stage), the gc will not occur even once ?

是的。如果年轻代和老年代没有被填充(在任何阶段),那么 gc 可能 不会发生(甚至一次)。由 JVM 运行时来管理内存,这包括决定何时(或是否)发生垃圾收集。

关于java - 是否始终调用 gc,即使堆空间在运行时连续可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34551348/

相关文章:

java - 在数据库中使用 Hibernate 和 H2 时出错

c# - 抑制 C# 垃圾回收

python - 切片 numpy 数组时减少内存使用

java - 等效于 Linux 上的数据保护 API

java - 带有 bouncycaSTLe 的随机损坏的垫 block

java - 关于 system.out,需要说明

java - 使用 Spring-Data-Rest 以 XML 而不是 JSON 的形式返回响应

java - UseConcMarkSweepGC 详细 gc 输出显示内存下降

java - 网络爬虫耗尽堆空间

java - 通过在垃圾收集之前使用反射来清理内容,安全地使用 String 作为密码