int expectedInitialRetainCount = expectedAutorelease ? 2 : 1;
// that will decrease the count IF it was pooled
int expectedFinalRetainCount = expectedAutorelease ?
expectedInitialRetainCount - 1 : expectedInitialRetainCount;
NSAutoreleasePool pool = NSAutoreleasePool.new_();
NSObject object = factory.create();
assertRetainCount(expectedInitialRetainCount, object);
// aliasing should increase the retain count, as the alias also owns it
NSObject alias = Rococoa.cast(object, NSObject.class);
assertSame(object.id(), alias.id());
assertRetainCount(expectedInitialRetainCount + 1, object);
assertRetainCount(expectedInitialRetainCount + 1, alias);
// wait until object has been GC'd
WeakReference<Object> reference = new WeakReference<Object>(object);
object = null;
while (reference.get() != null) {
gc();
}
gc();
// it should now have been release'd
assertRetainCount(expectedInitialRetainCount, alias);
// now let the pool go
pool.drain();
assertRetainCount(expectedFinalRetainCount, alias);
}