Skip to content

[BUG] Memory leak when constructing empty frozendicts #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
squahtx opened this issue Jul 15, 2022 · 5 comments
Closed

[BUG] Memory leak when constructing empty frozendicts #60

squahtx opened this issue Jul 15, 2022 · 5 comments
Labels
Type: Bug Something isn't working

Comments

@squahtx
Copy link

squahtx commented Jul 15, 2022

Similar to #55, frozendict() and frozendict({}) leak memory.

OS version: Ubuntu 20.04.4 LTS
Python3 version (python3 -V -V): Python 3.8.10

Steps to reproduce

Borrowing code from #55:

import resource
import frozendict

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

c = 0
while True:
    fz = frozendict.frozendict({})
    
    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

frozendict version: 2.3.2

iteration: 0, max rss: 11292 kb
iteration: 10000, max rss: 12188 kb
iteration: 20000, max rss: 12980 kb
iteration: 30000, max rss: 13772 kb
...
iteration: 3150000, max rss: 263252 kb
iteration: 3160000, max rss: 264044 kb
iteration: 3170000, max rss: 265100 kb
@squahtx
Copy link
Author

squahtx commented Jul 15, 2022

I think we might be missing a Py_DECREF(self) when we decide to return an empty frozendict in _frozendict_new?

PyObject* self = frozendict_new_barebone(type);
PyFrozenDictObject* mp = (PyFrozenDictObject*) self;
if (frozendict_update_common(self, arg, kwds)) {
Py_DECREF(self);
return NULL;
}
PyObject* empty = frozendict_create_empty(mp, type, use_empty_frozendict);
if (empty != NULL) {
return empty;
}

@Marco-Sulla
Copy link
Owner

Thank you for the report. Fixed in 81e163a can you confirm?

@squahtx
Copy link
Author

squahtx commented Jul 18, 2022

That seems to have fixed it. Thank for your the fast response!
Can we have a PyPI release with the fix?

@Marco-Sulla
Copy link
Owner

Done.

@squahtx
Copy link
Author

squahtx commented Jul 21, 2022

Thanks again for getting the bugs fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants