Interview question: Objects eligible for garbage collection

前端 未结 7 904
无人共我
无人共我 2020-12-02 19:03

Give the following code:

class A {
    Boolean b;
    A easyMethod(A a){
        a = null;
        return a;
    }
    public static void main(String [] args         


        
7条回答
  •  我在风中等你
    2020-12-02 19:54

    Can you please me explain me why a2 and a3 aren't being garbage collected ?

    Because a2 and a3 are not objects. They are variables. Variables are not collectable for the simple reason that they are not allocatable.

提交回复
热议问题