[Python-Dev] We got leaks!
Kevin Jacobs
jacobs@penguin.theopalgroup.com
Fri, 6 Dec 2002 20:31:45 -0500 (EST)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
--416156269-869349433-1039224705=:12728
Content-Type: TEXT/PLAIN; charset=US-ASCII
On Fri, 6 Dec 2002, Kevin Jacobs wrote:
> Here it is:
>
> import sys
> import cPickle
>
> dumped = cPickle.dumps(object())
> for i in range(10):
> cPickle.loads(dumped)
> print '*' * 10, 'total refs:', sys.gettotalrefcount()
>
> The leak occurs in cPickle.loads, but not in pickle.loads. It also does not
> depend on binary or non-binary mode of dumps(). It seems to require a
> new-style object to occur, but not one that implements a custom hash
> function as in the previously reported leak.
>
> This is all I have time for this evening... If the case(s) are not cracked
> tomorrow, I'll take a stab at dissecting the responsible C code.
I lied. Attached is a patch for this leak and several others in cPickle.c
(the diff around line 3118 to Instance_New is the culprit for the above test
case). Someone should check over my changes, since I'm getting a little
cross-eyed by now. This takes care of all leaks from the Python test suite,
though there are still 2 ref-counts leaking per loop when using the C
version of datetime.
Enjoy,
-Kevin
PS: If Tim doesn't apply this patch fairly instantly, I will, of course,
submit it to sourceforge. blah... blah... blah...
--
Kevin Jacobs
The OPAL Group - Enterprise Systems Architect
Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com
Fax: (216) 986-0714 WWW: http://www.theopalgroup.com
--416156269-869349433-1039224705=:12728
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="cpickle-refcnt.diff"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.44.0212062031450.12728@penguin.theopalgroup.com>
Content-Description:
Content-Disposition: attachment; filename="cpickle-refcnt.diff"
SW5kZXg6IE1vZHVsZXMvY1BpY2tsZS5jDQo9PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09DQpSQ1MgZmlsZTogL2N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