Issue #25582: Fixed 100 MB memory leak in test_ctypes.
This commit is contained in:
parent
ba270147e4
commit
b63902a748
|
@ -192,9 +192,19 @@ class PointersTestCase(unittest.TestCase):
|
||||||
LargeNamedType = type('T' * 2 ** 25, (Structure,), {})
|
LargeNamedType = type('T' * 2 ** 25, (Structure,), {})
|
||||||
self.assertTrue(POINTER(LargeNamedType))
|
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):
|
def test_pointer_type_str_name(self):
|
||||||
large_string = 'T' * 2 ** 25
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -135,5 +135,9 @@ class Structures(unittest.TestCase):
|
||||||
self.assertEqual(ret.top, top.value)
|
self.assertEqual(ret.top, top.value)
|
||||||
self.assertEqual(ret.bottom, bottom.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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue