Memory
Memory Management
Garbage Collector
import sys, gc
 
#cycle reference
def make_cycle():
    l = { }
    l[0] = l
 
def main():
    collected = gc.collect() # return number of collected and deallocated objects
    print "Garbage collector: collected %d objects." % (collected)
    print "Creating cycles..."
    for i in range(10):
        make_cycle()
    collected = gc.collect()
    print "Garbage collector: collected %d objects." % (collected)
 
if __name__ == "__main__":
    ret = main()
    sys.exit(ret)
		
Manual Garbage Collection
Reference