public synchronized long calculateObjectSize(Object obj) {
    // Breadth-first traversal instead of naive depth-first with recursive
    // implementation, so we don't blow the stack traversing long linked lists.
    boolean init = true;
    try {
      for (;;) {
        visit(obj, init);
        init = false;
        if (mPending.isEmpty()) {
          return mSize;
        }
        obj = mPending.removeFirst();
      }
    } finally {
      mVisited.clear();
      mPending.clear();
      mSize = 0;
    }
  }
@Test
  public void testCircular() {
    Circular c1 = new Circular();
    long size = mObjectSizeCalculator.calculateObjectSize(c1);
    c1.mCircular = c1;
    assertEquals(size, mObjectSizeCalculator.calculateObjectSize(c1));
  }