垃圾收集问题 [英] Garbage Collection question

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

问题描述

class A {
    private B b;
    public A() {
        this.b = new B(this);
    }
}

class B
{
  
    private A a;
    public B(A a) {
        this.a = a;
    }
}







有多少对象符合垃圾回收的条件垃圾收集器?




How many objects are eligible for garbage collection by the Garbage Collector?

推荐答案

代码中的对象在哪里?所以没有
Where is the object in your code? So none


你实例化了多少个对象?

这将帮助您确定答案。



A的构造函数定义对象B.

但是,构造函数A本身永远不会被调用。



这个你没有对象。
How many objects do you instantiate?
That will help you identify your answer.

The constructor for A defines the object B.
However, constructor A itself is never called.

This you have no objects.


你从来没有在meory中发起过一个对象使用
You have never initiated an object in the meory with the
new

关键字。因此,没有任何对象可以被垃圾收集器收集。

key word. Therefore is no object there which could be collecteed by the garbage collector.


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

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