Skip to content
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

copy_stream leaks memory (when compressing) #40

Closed
talkaminker opened this issue Feb 11, 2018 · 2 comments
Closed

copy_stream leaks memory (when compressing) #40

talkaminker opened this issue Feb 11, 2018 · 2 comments

Comments

@talkaminker
Copy link
Contributor

Same as https://github.com/indygreg/python-zstandard/issues/35
copy_steam leaks also on compression
copy_stream leaks a lot of memory when compressing.
The amount leaked seems to be proportional to the size of the input stream
changing 1024*1024 to 1024 leaks less memory

import os
import gc
import zstd
import tempfile
import resource

with tempfile.NamedTemporaryFile('wb', delete=False) as f:
    f.write(os.urandom(1024*1024))
input_path = f.name
f = tempfile.NamedTemporaryFile(delete=False); f.close()
output_path = f.name
for i in range(1001):
    with open(input_path, 'rb') as ifh, open(output_path, 'wb') as ofh:
        zstd.ZstdCompressor().copy_stream(ifh, ofh)
    if i % 100 == 0:
        print(i, resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
        gc.collect()
os.remove(input_path)
os.remove(output_path)

output:
0 12952
100 116052
200 219148
300 322460
400 425780
500 529092
600 632404
700 735716
800 839036
900 942348
1000 1045660

@vhavel
Copy link

vhavel commented Mar 1, 2018

When can we expect the fix (i.e. v0.8.2) to be released into pypi? Thanks!

indygreg added a commit that referenced this issue Mar 17, 2018
The PyObject holding the result of the read() operation never
had its refcount decreased. This created a leak.

Fixes #40.
indygreg added a commit that referenced this issue Mar 17, 2018
The PyObject holding the result of the read() operation never
had its refcount decreased. This created a leak.

Fixes #40.
@indygreg
Copy link
Owner

0.8.2 was just released to PyPI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants