'Regression test for https://github.com/astropy/astropy/pull/4539
This actually re-runs a small set of tests that I found, during
careful testing, exhibited the reference leaks fixed by #4539, but
now with reference counting around each test to ensure that the
leaks are fixed.'

@pytest.mark.skipif(str('not    HAVE_OBJGRAPH'))
def test_reference_leak(self, tmpdir):

    from .test_core import TestCore
    from .test_connect import TestMultipleHDU
    t1 = TestCore()
    t1.setup()
    try:
        with _refcounting('FITS_rec'):
            t1.test_add_del_columns2()
    finally:
        t1.teardown()
    del t1
    t2 = self.__class__()
    for test_name in ['test_recarray_to_bintablehdu', 'test_numpy_ndarray_to_bintablehdu', 'test_new_table_from_recarray', 'test_new_fitsrec']:
        t2.setup()
        try:
            with _refcounting('FITS_rec'):
                getattr(t2, test_name)()
        finally:
            t2.teardown()
    del t2
    t3 = TestMultipleHDU()
    t3.setup_class()
    try:
        with _refcounting('FITS_rec'):
            t3.test_read(tmpdir)
    finally:
        t3.teardown_class()
    del t3
