pyo3/pytests/tests/test_objstore.py
2023-10-26 21:04:49 +01:00

24 lines
563 B
Python

import gc
import sys
from pyo3_pytests.objstore import ObjStore
def test_objstore_doesnot_leak_memory():
N = 10000
message = b'\\(-"-;) Praying that memory leak would not happen..'
# PyPy does not have sys.getrefcount, provide a no-op lambda and don't
# check refcount on PyPy
getrefcount = getattr(sys, "getrefcount", lambda obj: 0)
before = getrefcount(message)
store = ObjStore()
for _ in range(N):
store.push(message)
del store
gc.collect()
after = getrefcount(message)
assert after - before == 0