[Python-checkins] cpython (2.7): Issue #25582: Fixed 100 MB memory leak in test_ctypes.

serhiy.storchaka python-checkins at python.org
Mon Nov 9 15:34:22 EST 2015


https://hg.python.org/cpython/rev/f14f6bce3321
changeset:   99020:f14f6bce3321
branch:      2.7
parent:      99013:2f2c52c9ff38
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Mon Nov 09 22:31:10 2015 +0200
summary:
  Issue #25582: Fixed 100 MB memory leak in test_ctypes.

files:
  Lib/ctypes/test/test_pointers.py |  12 +++++++++++-
  Lib/ctypes/test/test_win32.py    |   4 ++++
  2 files changed, 15 insertions(+), 1 deletions(-)


diff --git a/Lib/ctypes/test/test_pointers.py b/Lib/ctypes/test/test_pointers.py
--- a/Lib/ctypes/test/test_pointers.py
+++ b/Lib/ctypes/test/test_pointers.py
@@ -192,9 +192,19 @@
         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
--- a/Lib/ctypes/test/test_win32.py
+++ b/Lib/ctypes/test/test_win32.py
@@ -114,5 +114,9 @@
             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()

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list