Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: (untagged)
C#
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?
Posted
Updated 13-Mar-13 11:57am
v4
Comments
ZurdoDev 13-Mar-13 7:18am    
Is this a homework question? What do you think the answer is?
CPallini 13-Mar-13 7:40am    
None. There aren't objects in your code (I see only class definitions).
Keith Barrow 13-Mar-13 7:56am    
Seeing as you never instantiate A or B, none.
Manfred Rudolf Bihy 13-Mar-13 8:14am    
The exact same code was asked about yesterday, albeit the last time the OP at least included the code part where the instances were created.
This reeks strongly of homework.

Where is the object in your code? So none
 
Share this answer
 
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.
 
Share this answer
 
You have never initiated an object in the meory with the
C#
new
key word. Therefore is no object there which could be collecteed by the garbage collector.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900