I have an embedded Linux system with 256MB of RAM. There is a large codebase running on it, most in C++ but some utilities are in Python. We have a Python "package manager" that handles updates to the system using the Python apt module (we distribute our updates as .deb files). When running, this application uses a large portion of the system RAM. I am monitoring RAM usage with top, looking at the RSS for the Python process (maybe this is not a valid way to analyze process memory usage? Open to suggestions).
The line
cache = apt.Cache()
which is called periodically to check on the status of the system seems to consume about 20MB each time it is called, and it doesn't look like this memory is being returned. I tried deleting the cache object at the end of the function and running gc.collect(), that didn't seem to help much.
How can I reduce the memory usage of this program?
The platform is ARM Cortex A8, running Linux 3.2, Debian Wheezy and Python 2.7.3.