diff -r d70026504feb Lib/ctypes/test/test_pointers.py --- a/Lib/ctypes/test/test_pointers.py Sat Nov 07 18:06:24 2015 +0200 +++ b/Lib/ctypes/test/test_pointers.py Sat Nov 07 22:12:37 2015 +0200 @@ -195,9 +195,19 @@ class PointersTestCase(unittest.TestCase LargeNamedType = type('T' * 2 ** 25, (Structure,), {}) self.assertTrue(POINTER(LargeNamedType)) + # to not leak references, we must clean _pointer_type_cache + from ctypes import _pointer_type_cache + del _pointer_type_cache[LargeNamedType] + def test_pointer_type_str_name(self): large_string = 'T' * 2 ** 25 - self.assertTrue(POINTER(large_string)) + P = POINTER(large_string) + self.assertTrue(P) + + # to not leak references, we must clean _pointer_type_cache + from ctypes import _pointer_type_cache + del _pointer_type_cache[id(P)] + if __name__ == '__main__': unittest.main() diff -r d70026504feb Lib/ctypes/test/test_win32.py --- a/Lib/ctypes/test/test_win32.py Sat Nov 07 18:06:24 2015 +0200 +++ b/Lib/ctypes/test/test_win32.py Sat Nov 07 22:12:37 2015 +0200 @@ -135,5 +135,9 @@ class Structures(unittest.TestCase): self.assertEqual(ret.top, top.value) self.assertEqual(ret.bottom, bottom.value) + # to not leak references, we must clean _pointer_type_cache + from ctypes import _pointer_type_cache + del _pointer_type_cache[RECT] + if __name__ == '__main__': unittest.main()