]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #25582: Fixed 100 MB memory leak in test_ctypes.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 9 Nov 2015 20:31:10 +0000 (22:31 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 9 Nov 2015 20:31:10 +0000 (22:31 +0200)
Lib/ctypes/test/test_pointers.py
Lib/ctypes/test/test_win32.py

index e24a520dbe060653229638db812ffe99a641ac90..6eea58fb43b1761ed51a613bdf62f146580621dd 100644 (file)
@@ -192,9 +192,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()
index 5867b0592924256bda8aed40d586f99bcdea2056..da1624015e198c1e0f28cb7271655ae78f3df301 100644 (file)
@@ -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()