tiny script has memory leak

Discussion in 'Python' started by gry, May 11, 2012.

  1. gry

    gry Guest

    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...)
     
    gry, May 11, 2012
    #1
    1. Advertising

  2. gry

    Iain King Guest

    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
     
    Iain King, May 17, 2012
    #2
    1. Advertising

  3. gry <> writes:

    > 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()


    sys.version is '2.6.6 (r266:84292, Sep 15 2010, 16:22:56) \n[GCC 4.4.5]'
    here, and your script works like a charm. BTW, I would use f.write()
    instead of print >> f (which I think is deprecated).

    -- Alain.
     
    Alain Ketterlin, May 17, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9obiBNb29yZQ==?=

    KB 316775 reproes in .net 1.1 - XSLT with script has memory leak

    =?Utf-8?B?Sm9obiBNb29yZQ==?=, Nov 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,469
    Ken Cox [Microsoft MVP]
    Nov 11, 2004
  2. =?Utf-8?B?U3RldmUgQmVzYWxrZQ==?=

    KB 911309: memory leak w/ application that has custom URL's

    =?Utf-8?B?U3RldmUgQmVzYWxrZQ==?=, Jun 5, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    345
    bruce barker \(sqlwork.com\)
    Jun 5, 2006
  3. Sullivan WxPyQtKinter
    Replies:
    4
    Views:
    335
    Sullivan WxPyQtKinter
    Mar 5, 2006
  4. Replies:
    0
    Views:
    351
  5. Texas Bob
    Replies:
    0
    Views:
    234
    Texas Bob
    Jul 25, 2009
Loading...

Share This Page