Freeing the memory in Gtk?

mas at echo.fr.bbs mas at echo.fr.bbs
Wed Jul 12 12:50:04 EDT 2000


  Hello,

I've been using Glade and libglade for some days, and I like it so
much I'm probably going to do my next big thing with it.  Except I
have a problem, which follows.

  Suppose we have a GtkList, which is empty at first.  Now suppose we
fill it somewhat, inserting GtkListItem's into it.  Good, it works.
Now suppose we want to change the contents of this list, by removing
the items from it and inserting new ones into it.

  How do I free the memory allocated for the old items?  I mean, I
know I'm in Python, and I know I shouldn't worry about that, but my
process grows and grows.  Too much for me not to worry.

  Code snippet:
-----
from gtk import *
from gnome.ui import *
from GDK import *
from libglade import *
import time

def init ():
    global wtree_app, list, pb, centry
    wtree_app = GladeXML (gf, "app")
    list = wtree_app.get_widget ("list1")
[...]

[a callback function]
def chercher_site (obj):
    global id, list, pb, centry
    t = centry.get_text ()
    chd = {}
    list = wtree_app.get_widget ("list1")
##     l = list.children ()
##     for i in l:
##         i.destroy ()
##     list.remove_items (l)
    list.clear_items (0, -1)
    i = 0
    nb = 100
    pb.set_progress (0)
    for i in range (nb):
        id = id + 1
        li = GtkListItem (label=t + ' - ' + str (i))
        sites [li._o] = { 'id': id, 'label': t }
        li.show ()
        list.show ()
        list.append_items ([li])
        pb.set_progress ((i + 1.0) / nb)
##         while events_pending ():
##             mainiteration (TRUE)
##         time.sleep (0.25)
    pb.set_progress (0)
-----

  If by repeatedly clicking on the appropriate button I repeatedly
call the chercher_site () callback function, the process uses more and
more memory, until the system becomes unusable.

  The first set of comments denotes things that I tried without
success, the second one gives a way to force a GUI update even during
the execution of a callback function.

  Does anyone know the solution?  What am I doing wrong?  What am I
forgetting?  Where could I have found the answer?

Roland.
--
Roland Mas

Infinity contains more things than you think.  Everything, for a start.
  -- in Witches Abroad (Terry Pratchett)



More information about the Python-list mailing list