#235 Cyclic References and Garbage Collection

Companies:
T-Bank
Themes:
JavaJVMCode Review

Will objects A and B be deleted?

Java
class A {
    B b;
}

class B {
    A a;
}

public class Main {
    public static void main(String[] args) {
        A objA = new A();
        B objB = new B();

        objA.b = objB;
        objB.a = objA;

        objA = null;
        objB = null;

        // Will objects A and B be deleted?
        System.gc();
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in