[code.view]

[top] / python / PyMOTW / weakref / weakref_cycle.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """Using proxy to prevent cycles.
     """
     #end_pymotw_header
     
     import gc
     from pprint import pprint
     import weakref
     
     from weakref_graph import Graph, demo, collect_and_show_garbage
     
     gc.set_debug(gc.DEBUG_LEAK)
     
     print 'Setting up the cycle'
     print
     demo(Graph)
     
     print
     print 'Breaking the cycle and cleaning up garbage'
     print
     gc.garbage[0].set_next(None)
     while gc.garbage:
         del gc.garbage[0]
     print
     collect_and_show_garbage()
     

[top] / python / PyMOTW / weakref / weakref_cycle.py

contact | logmethods.com