tiny script has memory leak

Iain King iainking at gmail.com
Thu May 17 05:06:16 EDT 2012


On Friday, 11 May 2012 22:29:39 UTC+1, gry  wrote:
> 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...)

Ran OK for me, python 2.4.1 on Windows 7

Iain



More information about the Python-list mailing list