import gtk
import time
import os

def get_vm_size (pid):
    fd = open ('/proc/%d/status' % pid)
    for line in fd.readlines ():
	if line[:6] == "VmSize":
	    return int (line.split()[1])
	
win = gtk.Window ()

def do_test ():
    widget = gtk.Label ('1234')
    del widget
    
pid = os.getpid ()

# Warm up
for i in range (10):
    get_vm_size (pid)
    do_test ()

leaks = 0

def run_one (pid):
    before = get_vm_size (pid)
    do_test ()
    after = get_vm_size (pid)
    
    if before != after:
	leak = after-before
	return leak
    
    return 0

TIMES = 1024
for i in range (TIMES):
    leak = run_one (pid)
    if leak:
	leaks += leak

print 'Total leaked: %d KB' % (int(leaks))
print 'Per instance: %d B' % leaks

    


