#182 reported a mem leak and fixed by #185 , and #185 removed TIMESTAMP_TO_DT_CACHE, but the other module-level dict EXPRESSIONS has the same problem, it caches every unique expression forever.
Reproduction:
import os, gc, random
from datetime import datetime
from croniter.croniter import EXPRESSIONS
from croniter import croniter
def rss_mb():
with open(f'/proc/{os.getpid()}/statm') as f:
return int(f.read().split()[1]) * 4096 / 1024 / 1024
random.seed(42)
gc.collect()
print(f'Before: EXPRESSIONS={len(EXPRESSIONS)}, RSS={rss_mb():.1f}MB')
for i in range(100000):
expr = f'{random.randint(0,59)} {random.randint(0,23)} {random.randint(1,28)} * *'
start = datetime(random.randint(2010, 2030), random.randint(1, 12), random.randint(1, 28))
croniter(expr, start).get_next(datetime)
if (i+1) % 25000 == 0:
gc.collect()
print(f'{i+1}: EXPRESSIONS={len(EXPRESSIONS)}, RSS={rss_mb():.1f}MB')
Output:
Before: EXPRESSIONS=0, RSS=9.8MB
25000: EXPRESSIONS=18561, RSS=26.2MB
50000: EXPRESSIONS=28698, RSS=37.4MB
75000: EXPRESSIONS=34113, RSS=46.8MB
100000: EXPRESSIONS=37022, RSS=51.3MB
#182 reported a mem leak and fixed by #185 , and #185 removed
TIMESTAMP_TO_DT_CACHE, but the other module-level dictEXPRESSIONShas the same problem, it caches every unique expression forever.Reproduction:
Output: