Exemple #1
0
 def test_newinstance(self):
     class A(object):
         pass
     a = A()
     a.a = a
     gc.collect()
     del a
     self.assertNotEqual(gc.collect(), 0)
     class B(list):
         pass
     class C(B, A):
         pass
     a = C()
     a.a = a
     gc.collect()
     del a
     self.assertNotEqual(gc.collect(), 0)
     del B, C
     # If we don't clear the feedback array, the FDO system will hold
     # references to B and C, which prevent gc.collect() from collecting
     # them.
     if _llvm:
         _llvm.clear_feedback(self.test_newinstance)
     self.assertNotEqual(gc.collect(), 0)
     A.a = A()
     del A
     self.assertNotEqual(gc.collect(), 0)
     self.assertEqual(gc.collect(), 0)
Exemple #2
0
def dash_R_cleanup(fs, ps, pic, abcs):
    import gc, copy_reg
    import _strptime, linecache
    dircache = test_support.import_module('dircache', deprecated=True)
    import urlparse, urllib, urllib2, mimetypes, doctest
    import struct, filecmp
    from distutils.dir_util import _path_created

    # Clear the warnings registry, so they can be displayed again
    for mod in sys.modules.values():
        if hasattr(mod, '__warningregistry__'):
            del mod.__warningregistry__

    # Restore some original values.
    warnings.filters[:] = fs
    copy_reg.dispatch_table.clear()
    copy_reg.dispatch_table.update(ps)
    sys.path_importer_cache.clear()
    sys.path_importer_cache.update(pic)

    # clear type cache
    sys._clear_type_cache()

    # Clear ABC registries, restoring previously saved ABC registries.
    for abc, registry in abcs.items():
        abc._abc_registry = registry.copy()
        abc._abc_cache.clear()
        abc._abc_negative_cache.clear()

    # Clear assorted module caches.
    _path_created.clear()
    re.purge()
    _strptime._regex_cache.clear()
    urlparse.clear_cache()
    urllib.urlcleanup()
    urllib2.install_opener(None)
    dircache.reset()
    linecache.clearcache()
    mimetypes._default_mime_types()
    filecmp._cache.clear()
    struct._clearcache()
    doctest.master = None

    if _llvm:
        code_types = (types.CodeType, types.FunctionType, types.MethodType)
        for obj in gc.get_objects():
            if isinstance(obj, code_types):
                _llvm.clear_feedback(obj)

    # Collect cyclic trash.
    gc.collect()