tiny script has memory leak

gry georgeryoung at gmail.com
Fri May 11 17:29:39 EDT 2012


sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2
[gcc-4_3-branch revision 141291]]
I thought this script would be very lean and fast, but with a large
value for n (like 150000), it uses 26G of virtural memory, and things
start to crumble.

#!/usr/bin/env python
'''write a file of random integers.  args are: file-name how-many'''
import sys, random

f = open(sys.argv[1], 'w')
n = int(sys.argv[2])
for i in xrange(n):
    print >>f, random.randint(0, sys.maxint)
f.close()

What's using so much memory?
What would be a better way to do this?  (aside from checking arg
values and types, I know...)



More information about the Python-list mailing list