Skip to content

[BUG] Memory leak in __hash__() #55

@gusostow

Description

@gusostow

Welcome! You should write in your Bug Report:

I found a case where frozendict does not free memory. The old v1 implementation does free memory in this situation.

OS version (https://www.google.com/search?channel=fs&q=check+os+version&ie=utf-8&oe=utf-8):
your OS version

$ uname -r
3.10.0-1160.59.1.el7.x86_64

Python3 version (python3 -V -V):
your Python version

3.7.6

Steps to reproduce:

import resource
import frozendict

print("frozendict version:", frozendict.__version__)
print()

c = 0
while True:
    mapping = {}
    fz = frozendict.frozendict({i: i for i in range(1000)})
    none = mapping.setdefault(fz, None)

    if (c % 10000) == 0:
        max_rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
        print(f"iteration: {c}, max rss: {max_rss} kb")

    c += 1

Actual result (with the python stack trace if present):
the result you see

frozendict version: 2.3.0

iteration: 0, max rss: 32196 kb
iteration: 10000, max rss: 1793552 kb
iteration: 20000, max rss: 3554452 kb
iteration: 30000, max rss: 5315972 kb
iteration: 40000, max rss: 7076784 kb
iteration: 50000, max rss: 8838472 kb

Note that this will use up memory rather fast on your machine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: HighA blocking bug or an important featureType: BugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions