Unimporting modules, memory leak?

  • Thread starter Antonio Arauzo Azofra
  • Start date
A

Antonio Arauzo Azofra

Hello everybody,

Probably, this is being too demanding for Python, but it may be
useful to unimport modules to work with dynamic code (though not the
best, one example is [2]). In fact, it is supposed to be possible[1],
but I have detected it usually leaks memory.

When unimported in Linux, the simple C module attached (has no
functions, just the structure) leaks two memory pages

To see the test you can just put the files in a directory and:
python setupmod1.py install --install-lib .
python testMemory.py

Its output follows. First, the memory used before import. Second memory
used after the import. Third the number of references to that object is
checked before using del. Finally the memory used after unimporting.

-- Testing mod1 --
Mem. used: 1242 (gc: 0 )
Mem. used: 1244 (gc: 0 )
Check refs (should be = 2): 2
Mem. used: 1244 (gc: 0 )
-- Testing bigModule --
Mem. used: 1244 (gc: 0 )
Mem. used: 2686 (gc: 0 )
Check refs (should be = 2): 2
Mem. used: 1244 (gc: 0 )
-- Testing random --
Mem. used: 1244 (gc: 0 )
Mem. used: 1256 (gc: 0 )
Check refs (should be = 2): 2
Mem. used: 1256 (gc: 57 )

Unimporting attached "bigmodule.py" there are no memory leaks.
Unimporting python's random module it leaks some pages, but garbage
collector admit it can not free them.

If a module with the same name that the unimported module is imported,
the pages are reused. While, if this same module is loaded with another
name, they are not freed, and the program grows with each module
imported/unimported

Is this a Python bug? A Linux bug? Am i missing some way of freeing that
memory used by C module?

[1] http://mail.python.org/pipermail/python-list/1999-May/002669.html
[2] http://ax5.com/antonio/orangesnns
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top