def check_for_obj_leakage(f, *args, **kwargs):
 f()
 gc.collect()
 gc.collect()
 gc.collect()
 f()
 gc.collect()
 gc.collect()
 gc.collect()
 r1 = gc.get_objects()
 f()
 gc.collect()
 gc.collect()
 gc.collect()
 r2 = gc.get_objects()
 d2 = dict([(id(x), x) for x in r2])
 del d2[id(r1)]
 for o in r1:
  if (id(o) in d2):
   del d2[id(o)]
 return (((len(r2) - len(r1)) - 1), d2)

def check_for_obj_leakage ( f , * args , ** kwargs ) : f ( ) gc . collect ( ) gc . collect ( ) gc . collect ( ) f ( ) gc . collect ( ) gc . collect ( ) gc . collect ( ) r1 = gc . get_objects ( ) f ( ) gc . collect ( ) gc . collect ( ) gc . collect ( ) r2 = gc . get_objects ( ) d2 = dict ( [ ( id ( x ) , x ) for x in r2 ] ) del d2 [ id ( r1 ) ] for o in r1 : if ( id ( o ) in d2 ) : del d2 [ id ( o ) ] return ( ( ( len ( r2 ) - len ( r1 ) ) - 1 ) , d2 )
the idea is that i am going to invoke f() .