Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Homework
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 1:57am
Edited 13-Mar-13 12:57pm
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 325
1 DamithSL 300
2 Sergey Alexandrovich Kryukov 289
3 CPallini 235
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 13 Mar 2013
Copyright © CodeProject, 1999-2014
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