#!/usr/bin/python

import gtk, gobject, gc, sys

if len(sys.argv) != 2:
    print 'usage: %s bigimage' % sys.argv[0]
    sys.exit(1)

def create_window():
    gc.collect()
    window = gtk.Window()
    box = gtk.HBox()
    button = gtk.Button('eat more memory')
    box.pixbuf = gtk.gdk.pixbuf_new_from_file(sys.argv[1])
    button.connect('clicked', close)
    box.add(button)
    window.add(box)
    window.show_all()
    ## the following line triggers the leak
    button.linkto = box
    
def close(button):
    window = button.get_toplevel()
    ## we remove ourselves here explicitly as winow.destroy() disconnects all
    ## signal handlers and with that breaks the cycle
    window.remove(window.child)
    window.destroy()
    del window
    create_window()

create_window()
gtk.main()

