tkinter: not freeing memory like I'd expect

B

Benjamin Rutt

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top