什么触发垃圾收集 [英] What triggers garbage collection

查看:118
本文介绍了什么触发垃圾收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道所有的垃圾收集。但是究竟是什么告诉JRE现在是垃圾收集的时候了?它是否像一些事件或时间间隔?

解决方案

HotSpot的垃圾收集已经发展成为一项极其复杂的业务,了解详情。因此你不能得到一个简单的答案;一些触发器是:


  1. 占用每个对象生成达到阈值;
  2. 内存分配请求在特定的一代失败;

  3. 整体堆占用率达到阈值



  4. 请注意,您甚至没有指定您感兴趣的垃圾收集的类型:有一个次要集合和一个主要 >收集,技术上他们是非常不同的。您还没有指定您想要的垃圾收集器:HotSpot有四个垃圾收集器供您选择。



    如果您是Java初学者,是a)在日常编程中,不要担心;和b)如果你想学习,你必须深入挖掘


    I know what all gets garbage collected. But what exactly tells JRE that it is time for garbage collection? Is it like some event or time interval?

    解决方案

    HotSpot's garbage collection has grown into an exceedingly complex business, which even its creators struggle to understand in full detail. Therefore you can't be given a simple answer; some triggers are:

    1. occupation of each object generation reaching a threshold;
    2. a memory allocation request in a specific generation failing;
    3. overall heap occupation reaching a threshold.

    Note that you haven't even specified what kind of garbage collection you are interested in: there is a minor collection and a major collection, and technologically they are very different. You have also not specified which Garbage Collector you have in mind: HotSpot has four of them to choose from.

    If you are a beginner with Java, the best advice to give is a) in day-to-day programming, don't worry about it; and b) if you want to learn, you'll have to dig deep.

    这篇关于什么触发垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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