Click here to Skip to main content
11,718,016 members (81,386 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: (untagged)
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 13-Mar-13 0:57am
Edited 13-Mar-13 11:57am
v4
Comments
ryanb31 at 13-Mar-13 7:18am
   
Is this a homework question? What do you think the answer is?
CPallini at 13-Mar-13 7:40am
   
None. There aren't objects in your code (I see only class definitions).
Keith Barrow at 13-Mar-13 7:56am
   
Seeing as you never instantiate A or B, none.
Manfred R. Bihy at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Where is the object in your code? So none
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 215
1 F-ES Sitecore 210
2 Maciej Los 140
3 Jochen Arndt 120
4 Andy Lanng 115
0 Sergey Alexandrovich Kryukov 1,649
1 OriginalGriff 535
2 Maciej Los 529
3 Richard MacCutchan 440
4 CHill60 415


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 13 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100