#NEWLINE# def prune( self ) : #NEWLINE# #INDENT# 'prune unreferenced, non-dirty states.' #NEWLINE# ref_count = len ( self ) #NEWLINE# dirty = [ s . obj ( ) for s in self . all_states ( ) if s . modified ] #NEWLINE# keepers = weakref . WeakValueDictionary ( ) #NEWLINE# keepers . update ( self ) #NEWLINE# self . _dict . clear ( ) #NEWLINE# self . _dict . update ( keepers ) #NEWLINE# self . modified = bool ( ref_count ) #NEWLINE# return ( ref_count - len ( self ) )