@Test
public void testBusGC() throws Exception {
Pipeline pipe = new Pipeline("test playbin");
pipe.play();
Bus bus = pipe.getBus();
GObjectStruct struct = new GObjectStruct(bus);
int refcnt = struct.ref_count;
assertTrue(refcnt > 1);
// reget the Bus - should return the same object and not increment ref count
Bus bus2 = pipe.getBus();
assertTrue("Did not get same Bus object", bus == bus2);
struct.read(); // update struct fields
assertEquals("ref_count not equal", refcnt, struct.ref_count);
bus2 = null;
WeakReference<Bus> bref = new WeakReference<Bus>(bus);
bus = null;
// Since the pipeline holds a reference to the GstBus, the proxy should not be disposed
assertFalse("bus disposed prematurely", waitGC(bref));
assertFalse("ref_count decremented prematurely", waitRefCnt(struct, refcnt - 1));
WeakReference<GObject> pref = new WeakReference<GObject>(pipe);
pipe.stop();
bus = pipe.getBus();
bref = new WeakReference<Bus>(bus);
pipe = null;
assertTrue("pipe not disposed", waitGC(pref));
struct.read();
System.out.println("bus ref_count=" + struct.ref_count);
bus = null;
assertTrue("bus not disposed", waitGC(bref));
// This is a bit dangerous, since that memory could have been reused
assertTrue("ref_count not decremented", waitRefCnt(struct, 0));