<s> from weakref import WeakKeyDictionary , WeakValueDictionary <EOL> class S ( object ) : <EOL> def __init__ ( self , n ) : <EOL> self . n = n <EOL> def __hash__ ( self ) : <EOL> return hash ( self . n ) <EOL> def __eq__ ( self , rhs ) : <EOL> return self . n == rhs . n <EOL> def test ( d ) : <EOL> print "<STR_LIT>" , d . __class__ <EOL> k , v = None , None <EOL> for i in xrange ( <NUM_LIT:10> ) : <EOL> print i <EOL> for j in xrange ( <NUM_LIT:100> ) : <EOL> k , v = S ( <NUM_LIT:0> ) , S ( <NUM_LIT:0> ) <EOL> d [ k ] = v <EOL> import gc <EOL> gc . collect ( ) <EOL> print len ( d . keys ( ) ) , k in d <EOL> test ( WeakKeyDictionary ( ) ) <EOL> test ( WeakValueDictionary ( ) ) </s>
