This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ateng
Recipients ateng
Date 2014-03-18.14:03:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1395151435.82.0.675671732533.issue20967@psf.upfronthosting.co.za>
In-reply-to
Content
A particular usage pattern of hashlib will cause a memory leak.

This leaks:
import hashlib
import sys

if __name__ == '__main__':
    data_sha1 = "hello world"
    data_md5 = "hello world"
    for i in xrange(int(1e6)):
        hashlib.sha1(data_sha1)
        hashlib.md5(data_md5)

        if i % 1000 == 0:
            print sys.getrefcount(data_sha1), ",", sys.getrefcount(data_md5)

-------
this doesn't leak:

import hashlib
import sys


if __name__ == '__main__':
    data_sha1 = "hello world"
    data_md5 = "hello world"
    for i in xrange(int(1e6)):
        sha1 = hashlib.sha1()
        sha1.update(data_sha1)
		md5 = hashlib.md5()
		md5.update(data_md5)
        
        if i % 1000 == 0:
            print sys.getrefcount(data_sha1), ", ", sys.getrefcount(data_md5)


See attached for leak memory profiling in linux
History
Date User Action Args
2014-03-18 14:03:55atengsetrecipients: + ateng
2014-03-18 14:03:55atengsetmessageid: <1395151435.82.0.675671732533.issue20967@psf.upfronthosting.co.za>
2014-03-18 14:03:55atenglinkissue20967 messages
2014-03-18 14:03:55atengcreate