memory freeing

Peter Saffrey theoryboy at my-deja.com
Sun Jul 21 12:08:50 EDT 2002


I am writing a graph based application in Python. The application
requires each node (a Python object) stores information about routes
to get from one node to another.

The routes are stored in a hash of lists, of which there are 2 for
each node. The can_reach hash has reachable node names (strings) as
keys, and lists of lists of transitions (also strings) as values. The
reachable_from hash is the same structure but stores routes to the
storing node, rather than originating from it. The values are lists of
lists, because I need to store several alternative routes between the
nodes for efficient searching through the graph.

For example, a node s0 may have a can_reach hash that looks like this:

{'s1': [['t0','t1'],['t3','t4']], 's2': [['t4','t5','t6']]}

indicating that s0 can reach s1 by routes ['t0','t1'] or ['t3','t4'].
s0 can reach s2 by route ['t4','t5','t6']. This could equally be a
reachable_from hash, indicating that s0 can be reached from s1 by
routes ['t0','t1'] or ['t3','t4'] and s0 can be reached from s2 by
route ['t4','t5','t6'].

I realise the reachable_from hash is repetition, but I need it to
generate the can_reach hashes.

I have found, perhaps not surprisingly, that in large graphs these
hashes grow very large. Since I only need the reachable_from hashes
for can_reach generation, I was going to delete all reachable_from
hashes once I had the can_reach routes I need.

I set up a loop to assign "None" values into all the reachable_from
hashes, but the memory displayed by my system monitor (gkrellm) does
not seem to indicate that I've gained any memory. Do I need to do
anything more specific to order Python to return this memory to me?
Obviously many of the routes have shared parts, but I use the
concatenate (+) operator when building the lists, and I thought this
generated new list copies. Apart from anything else, each hash and the
pointers to the lists of lists should be separate objects, and just
removing these ought to give me a few megabytes, but I don't seem to
be getting any at all.

The Python website has some rather advanced advice on homemade
reference management, which does not seem to suit my needs. Any ideas?

Regards,

Peter Saffrey

-- 
PhD student
Computing Science Department
University of Glasgow



More information about the Python-list mailing list