example one application of weak references is to create caches of recently computed results for instanceif function takes long time to compute resultit might make sense to cache these results and to reuse them as long as they are still in use someplace in the application for example_resultcache def foocache( )if resultcache has_key( ) _resultcache[ ](get weak ref and dereference it if is not nonereturn foo(x_resultcache[xweakref ref(rreturn notes only class instancesfunctionsmethodssetsfrozen setsfilesgeneratorstype objectsand certain object types defined in library modules (for examplesocketsarraysand regular expression patternssupport weak references built-in functions and most built-in types such as listsdictionariesstringsand numbers cannot be used if iteration is ever used on weakkeydictionary or weakvaluedictionarygreat care should be taken to ensure that the dictionary does not change size because this may produce bizarre side effects such as items mysteriously disappearing from the dictionary for no apparent reason if an exception occurs during the execution of callback registered with ref(or proxy()the exception is printed to standard error and ignored weak references are hashable as long as the original object is hashable moreoverthe weak reference will maintain its hash value after the original object has been deletedprovided that the original hash value is computed while the object still exists weak references can be tested for equality but not for ordering if the objects are still alivereferences are equal if the underlying objects have the same value otherwisereferences are equal if they are the same reference lib fl ff