[ python-Bugs-1399099 ] i get a memory leak after using split() function on windows

SourceForge.net noreply at sourceforge.net
Sat Jan 7 16:54:43 CET 2006


Bugs item #1399099, was opened at 2006-01-07 19:04
Message generated for change (Comment added) made by perky
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1399099&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Leo Jay (leojay)
Assigned to: Nobody/Anonymous (nobody)
Summary: i get a memory leak after using split() function on windows

Initial Comment:
my environment is: python 2.4.2 on windows xp 
professional with sp2

what i do is just open a text file and count how many 
lines in that file:

D:\>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for 
more information.
>>> f = file('b.txt', 'rt')   # the size of b.txt is 
about 100 mega bytes
>>> print len(f.read().split('\n'))
899830
>>> f.close()
>>> del f
>>>

after these steps, the task manager shows that the 
python process still hog about 125 mega bytes memory. 
and the python don't release these memory until i 
quit the python.

but i find that if i remove the split() function,  
python acts right:

D:\>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for 
more information.
>>> f = file('b.txt', 'rt')
>>> print len(f.read())
95867667
>>>


so, is there something wrong with the split function? 
or it's just my misuse of split?


Best Regards, 
Leo Jay

----------------------------------------------------------------------

>Comment By: Hye-Shik Chang (perky)
Date: 2006-01-08 00:54

Message:
Logged In: YES 
user_id=55188

That's came from pymalloc's behavior.
Pymalloc never frees allocated memory in heap. For more
informations about this, see a mailing list thread
http://mail.python.org/pipermail/python-dev/2004-October/049480.html

The usual way to resolve the problem is to utilize iterator
style loops instead of reading the whole data at a time.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1399099&group_id=5470


More information about the Python-bugs-list mailing list