It would depend on if the object references in A and B are the same object references within each other. After you edited the example to include how A and B were instantiated (newed up), there IS NOT a memory leak in your example because the instances created of each are not the same instances (different memory reference).
It would be possible to create a memory leak in a case like this, depending on how the two classes are constructed or instantiated. The definition of the classes given above doesn't have enough information to determine if a memory leak is present.
For example, given the following class definitions:
class A extends Activity{
private B objectB;
public void setB(B b){
objectB = b;
}
}
class B{
private A objectA;
public B(A a){
objectA = a;
}
}
If you then created a Test class instantiating A and B as shown here:
class Test(){
public static void main(String... args){
A a = new A();
B b = new B(a);
a.setB(b);
}
}
In this case, a memory leak has been introduced because as B is instantiated, it is passed a reference to A and then we explicitly set B in A to the same B holding a reference to this instance of A.
If we change the code in Test by one line:
class Test(){
public static void main(String... args){
A a = new A();
B b = new B(a);
a.setB(new B()); //Modified this line
}
}
Now we no longer have a memory leak, as the B we pass to A is not the same instance as the B holding a reference to A.