@contextlib.contextmanager
def _refcounting(type_):

    gc.collect()
    refcount = len(objgraph.by_type(type_))
    yield refcount
    gc.collect()
    assert len(objgraph.by_type(type_)) <= refcount, \
            "More {0!r} objects still in memory than before."
Perform the body of a with statement with reference counting for the
dataset/ETHPy150Open spacetelescope/PyFITS/pyfits/tests/test_table.py/_refcounting