blunders
blunders

Reputation: 3669

How does Python handle memory?

I've been looking at a in-memory database -- and it got me thinking, how does Python handle IO that's not tied to a connection (and even data that is); for example, hashes, sets, etc.; is this a config somewhere, or is it dynamically managed based on resources; are there "easy" ways to view the effect resources are having on a real program, and simulate what the performance hit would be differing hardware setups?

NOTE: If it matters, Redis is the in-memory data store I'm looking at; there's an implementation of a wrapper for Redis datatypes so they mimic the datatypes found in Python.

Upvotes: 4

Views: 549

Answers (2)

Bill Gribble
Bill Gribble

Reputation: 1797

Not exactly what you're asking for, but Dowser is a Python tool for interactively browsing the memory usage of your running program. Very useful in understanding memory usage and allocation patterns.

http://www.aminus.net/wiki/Dowser

Upvotes: 1

Martin v. Löwis
Martin v. Löwis

Reputation: 127547

Python allocates all memory that the application asks for. There is not much room for policy. The only issue is when to release memory. (C)Python immediately releases all memory that is not referenced anymore (this is also not tunable). Memory that is referenced only from itself (ie. cycles) are released by the garbage collector; this has tunable settings.

It is the operating system's decision to write some of the memory into the pagefile.

Upvotes: 7

Related Questions