Memory Leak after Py_Finalize()

Discussion in 'Python' started by Tom, Mar 26, 2009.

  1. Tom

    Tom Guest

    Hi,
    I have ported Python, numarray and numpy to the PharLap Embedded
    Operating System. Python 2.5.2 numpy 1.3.0b1
    My problem is the massive memory loss coming back after Py_Finalize()
    when using numpy. I have seen similar posts but am unclear how to
    proceed. Here are my symptomns:-

    Py_Initialize()
    Py_Main()
    >>>> import numpy

    Py_Finalize()

    This gives me a 2.34 MB memory loss each time through. Its similar for
    numarray.
    Do I need to do something before coming back from Py_Main ? (like
    setting all the reference counts to 0 and forcing the garbage
    collector to run). Doing a >>> del numpy is not enough.
    I understand there is a memory loss when stopping and starting Python
    (I observe it to be about 70K) - my problem is that I dont know how to
    shutdown numpy cleanly - I want the opposite of "import numpy".
     
    Tom, Mar 26, 2009
    #1
    1. Advertising

  2. En Thu, 26 Mar 2009 14:51:00 -0300, Tom <> escribió:

    > I have ported Python, numarray and numpy to the PharLap Embedded
    > Operating System. Python 2.5.2 numpy 1.3.0b1
    > My problem is the massive memory loss coming back after Py_Finalize()
    > when using numpy. I have seen similar posts but am unclear how to
    > proceed. Here are my symptomns:-
    >
    > Py_Initialize()
    > Py_Main()
    >>>>> import numpy

    > Py_Finalize()
    >
    > This gives me a 2.34 MB memory loss each time through. Its similar for
    > numarray.


    I'd ask in a numpy specific forum.

    > Do I need to do something before coming back from Py_Main ? (like
    > setting all the reference counts to 0 and forcing the garbage
    > collector to run). Doing a >>> del numpy is not enough.


    I'm afraid there isn't much you can do -- calling gc.collect() should not
    hurt, but I don't think it would help a lot either.

    > I understand there is a memory loss when stopping and starting Python
    > (I observe it to be about 70K) - my problem is that I dont know how to
    > shutdown numpy cleanly - I want the opposite of "import numpy".


    Unfortunately, the Python API doesn't have an "uninitialize module"
    function/callback (not before 3.0). A lot of modules allocate memory upon
    initialization and never release it; some do that always, even if it has
    already been initialized. (Even worse, some modules carelessly store
    Python objects as static variables; using an old instance with a new
    interpreter is likely to crash Python...)
    So, if at all possible, try to avoid calling Py_Initialize and Py_Finalize
    more than once.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Mar 28, 2009
    #2
    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. Kari Hallfast
    Replies:
    2
    Views:
    457
    Harri Pesonen
    Oct 23, 2003
  2. Roman Suzi
    Replies:
    0
    Views:
    449
    Roman Suzi
    Jan 8, 2005
  3. Roman Suzi
    Replies:
    0
    Views:
    386
    Roman Suzi
    Jan 10, 2005
  4. cham
    Replies:
    5
    Views:
    786
  5. tom_caton
    Replies:
    0
    Views:
    404
    tom_caton
    Mar 27, 2009
Loading...

Share This Page