tkinter: not freeing memory like I'd expect

Benjamin Rutt rutt at bmi.osu.edu
Thu Mar 30 14:56:25 EST 2006


I have a bunch (e.g. 40) of tkinter Text objects in a gui on a linux
machine, tracking monitoring info per host.  They accumulate up to
500MB of text data (according to /bin/top) over time reading from
sockets.  I want to release this memory first by clearing all the text
contents, but keeping the Text objects in the GUI, via a callback
like:

def erase_all_text():
    for h in known_hosts_texts.keys():
        t = known_hosts_texts[h]
        t.config(state=NORMAL)
        t.delete('1.0',END)
        t.config(state=DISABLED)

But after calling the function, although the texts are cleared, no
memory is released according to /bin/top (the process is still 500MB
large).  Next, I try to remove all objects from the GUI, in the hope
that will free the memory:

def clear_all():
    global known_hosts
    global known_hosts_frames
    global known_hosts_texts

    known_hosts = {}
    known_hosts_frames = {}
    known_hosts_texts = {}

    for w in frametop.children.values():
        w.destroy() 

Got those last 2 lines from a Fredrik Lundh post I think.  But again,
the process is still 500MB large.  

I should point out that the erase_all_text() and clear_all() do what
they're told for the GUI, appearance-wise, it's just that I'd expect
the memory footprint to be reduced when they are called.  The lack of
a reduction eats up my memory space and causes the out-of-memory linux
killer to fire up eventually.  Am I doing anything wrong in either of
my approaches?  Or should I not expect memory to be released?
-- 
Benjamin Rutt



More information about the Python-list mailing list