You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
code to reproduce the results. run with pytest -s for best results.
from memory_profiler import profile
import gc
from memoization import cached
import random
import hashlib
class MemoizeClass:
def __int__(self):
self.unique = random.randint(0, 4000000000000)
@cached(max_size=1362)
def get_something(self, param):
return [param] * (2*10**5)
@profile
def test_memoization_cache():
print("\n")
c = MemoizeClass()
for i in range(1000):
c.get_something(random.randint(0, 4000000000000))
print(c.get_something.cache_info())
c = MemoizeClass()
for i in range(1000):
c.get_something(random.randint(0, 4000000000000))
print(c.get_something.cache_info())
del c
print(f"found some Garbage:{len(gc.garbage)} items")
print(f"collected: {gc.collect()}")
c = MemoizeClass()
for i in range(1000):
c.get_something(random.randint(0, 4000000000000))
print(c.get_something.cache_info())
print(len(list(c.get_something.cache_items())))
print("############## flushing the cache ################")
c.get_something.cache_clear()
print(len(list(c.get_something.cache_items())))
print(c.get_something.cache_info())
print(f"found some Garbage:{len(gc.garbage)} items")
print(f"collected: {gc.collect()}")
c = MemoizeClass()
for i in range(1000):
c.get_something(random.randint(0, 4000000000000))
print(c.get_something.cache_info())
The text was updated successfully, but these errors were encountered:
from memory_profiler import memory_usage,profile
import gc
from functools import lru_cache
import random
import hashlib
class MemoizeClass:
def __int__(self):
self.unique = random.randint(0, 4000000000000)
@lru_cache(maxsize=1362)
def get_something(self, param):
return [param] * (2*10**5)
@profile
def test_memoization_cache():
print("\n")
c = MemoizeClass()
for i in range(1000):
c.get_something(random.randint(0, 4000000000000))
print(c.get_something.cache_info())
c = MemoizeClass()
for i in range(1000):
c.get_something(random.randint(0, 4000000000000))
print(c.get_something.cache_info())
del c
print(f"found some Garbage:{len(gc.garbage)} items")
print(f"collected: {gc.collect()}")
c = MemoizeClass()
for i in range(1000):
c.get_something(random.randint(0, 4000000000000))
print(c.get_something.cache_info())
c.get_something.cache_clear()
print("############## flushing the cache ################")
print(c.get_something.cache_info())
print(f"found some Garbage:{len(gc.garbage)} items")
print(f"collected: {gc.collect()}")
c = MemoizeClass()
for i in range(1000):
c.get_something(random.randint(0, 4000000000000))
print(c.get_something.cache_info())
Looking at the profiler output, it seems like cached decorator is not releasing memory:
environment :
python 3.9.5
memoization: 0.4.0
code to reproduce the results. run with
pytest -s
for best results.The text was updated successfully, but these errors were encountered: