From: Serhiy Storchaka Date: Mon, 9 Nov 2015 20:31:10 +0000 (+0200) Subject: Issue #25582: Fixed 100 MB memory leak in test_ctypes. X-Git-Tag: v2.7.11rc1~38 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bab1f851cc455d08aa2cf5d1b883fd4772d5a4bf;p=python Issue #25582: Fixed 100 MB memory leak in test_ctypes. --- diff --git a/Lib/ctypes/test/test_pointers.py b/Lib/ctypes/test/test_pointers.py index 5cdde6813e..6915cda2bd 100644 --- a/Lib/ctypes/test/test_pointers.py +++ b/Lib/ctypes/test/test_pointers.py @@ -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() diff --git a/Lib/ctypes/test/test_win32.py b/Lib/ctypes/test/test_win32.py index ff083862cc..d22e139a3f 100644 --- a/Lib/ctypes/test/test_win32.py +++ b/Lib/ctypes/test/test_win32.py @@ -114,5 +114,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()