[Tutor] Shelve doesn't free up memory

Timo timomlists at gmail.com
Mon Mar 30 09:54:10 CEST 2009

Hello, I have a PyGTK application where the user is able to click on a 
button, then a new dialog pops up with a treeview and the program fills 
this view with data from a shelve.
Everything works, the data is being added to the treeview. The only 
problem is, that when I close the dialog, it doesn't free the memory. So 
when I click the button again, the same amount of memory is added being 
used. Then close the window, click again, again the same amount of 
memory, and so on...
Now it only takes about 5 to 8 mb, but this shouldn't be.
I do call the shelve.close(), but that doesn't do it apparently. Do I 
need to do something when I close my window?

Here are parts of the code:

# Result window => Called when button is clicked
import Results

class ResultWindow:
    def __init__(self):
        # Build the dialog and the treeview...


    def get_results(self):

        for person in self.persons:
            dics = Results.read_result(person)
            if not dics:
            for dic in dics:
                date = dic['date']
                point = dic['point']
                place = dic['place']
                out = dic['out']

                self.liststore.append([date, point, place, out])

# Results file
import shelve

def read_result(person):
    results = []

    s = shelve.open(RESULTFILE)
        results = s[person]
    except KeyError:
#        print "No results for this person"

    return results

More information about the Tutor mailing list