Python embedded in C & memory releasing

Tom Anderson twic at urchin.earth.li
Wed Sep 24 13:09:51 EDT 2003


On 23 Sep 2003, lebo wrote:

> I'm trying to understand how Python handles memory usage and dynamic
> object loading and unloading.  Problem to solve? Build a very low
> memory footprint (non-GUI) Python application for Unix/Windows. Why
> use Python? End user flexibility.
>
> So far it seems that (on Windows):
> (1) memory increases when you import <module>. Expected behaviour.
> (2) memory does not release when you del <module>. Why not?  Is Python
> not releasing the memory or is it the OS not releasing memory?
>
> So then I tried embedded Python in C:
> (1) c application base 1.6MBytes (a good number)
> (2) Call Python function from c application - memory up to 2.6MByte
> (OK number)
> (3) Python function exits but memory usage stays at 2.6MByte
>
> Why is memory not releasing? How can I tell if this Python behaviour
> or OS behaviour?

this is how most runtime systems handle memory. they have a certain amount
of space allocated, and if they run out, they ask the OS for more, but
they never give it back. i think this is what most implementations of
malloc/free do; it's certainly what java does.

what you want is some way to tell python to give back some or all of its
spare memory. i'm not aware of such a thing myself.

tom

-- 
unconstrained by any considerations of humanity or decency





More information about the Python-list mailing list