
import gc
import resource
import sys

from gi.repository import Gtk
from gi.repository import GObject

def _destroy_cb(ignore1, ignore2):
    Gtk.main_quit()

tree = Gtk.TreeView()
total = 0
count = 0

def _timeout_cb():
    global total
    global count
    if total % 1000 == 0:
        gc.collect()
        count += 1
        print "%.3d) %s" % (count,
                           resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
    total += 100

    model = tree.get_model()
    for row in model:
        row[1] = range(100)

    return 1

def _data_func(col, txt, model, _iter, data):
    foo = model[_iter][1]
    return

def main():
    window = Gtk.Window()
    window.connect("delete-event", _destroy_cb)

    model = Gtk.ListStore(str, object)
    for i in range(20):
        model.append([str(i), range(100)])

    col = Gtk.TreeViewColumn("Name")
    txt = Gtk.CellRendererText()
    col.set_cell_data_func(txt, _data_func, None)
    col.pack_start(txt, True)
    col.add_attribute(txt, "markup", 0)

    tree.set_model(model)
    tree.append_column(col)

    window.add(tree)
    window.show_all()

    GObject.timeout_add(100, _timeout_cb)

    Gtk.main()

if __name__ == '__main__':
    main()
