import sys import gc try: import win32process except: win32process = None def foo(s): d = range(100000) try: raise Exception() except: # Line 1: uncomment to show collector leaving memory s.e = sys.exc_info() pass def bar(): s = O() foo(s) class O(object): pass for x in xrange(100000): for y in xrange(100): bar() # Line 2: uncomment to show collector only collecting half #gc.collect() if win32process: proc = win32process.GetCurrentProcess() r = win32process.GetProcessMemoryInfo(proc) print r['WorkingSetSize']