[Python-Dev] Reduce memory footprint of Python

Benjamin Peterson benjamin at python.org
Sun Oct 6 17:41:23 CEST 2013


2013/10/6 Victor Stinner <victor.stinner at gmail.com>:
> Hi,
>
> Slowly, I'm trying to see if it would be possible to reduce the memory
> footprint of Python using the tracemalloc module.
>
> First, I noticed that linecache can allocate more than 2 MB. What do
> you think of adding a registry of "clear cache" functions? For
> exemple, re.purge() and linecache.clearcache(). gc.collect() clears
> free lists. I don't know if gc.collect() should be related to this new
> registy (clear all caches) or not.

What is the usecase for minimizing the memory usage of Python in the
middle of a program?

>
> The dictionary of interned Unicode strings can be large: up to 1.5 MB
> (with +30,000 strings). Just the dictionary, excluding size of
> strings. Is the size normal or not? Using tracemalloc, this dictionary
> is usually to largest memory block.

1.5 MB is sort of a pittance.

>
> unittest doesn't look to release memory (the TestCase class) after the
> execution of a test.

Is it important to optimize unittests for memory usage?


-- 
Regards,
Benjamin


More information about the Python-Dev mailing list