to illustrateconsider the following examplewhich sets the name to different object on each assignmentx 'shrubberyx [ reclaim now (unless referenced elsewherereclaim 'shrubberynow reclaim now firstnotice that is set to different type of object each time againthough this is not really the casethe effect is as though the type of is changing over time rememberin python types live with objectsnot names because names are just generic references to objectsthis sort of code works naturally secondnotice that references to objects are discarded along the way each time is assigned to new objectpython reclaims the prior object' space for instancewhen it is assigned the string 'shrubbery'the object is immediately reclaimed (assuming it is not referenced anywhere else)--that isthe object' space is automatically thrown back into the free space poolto be reused for future object internallypython accomplishes this feat by keeping counter in every object that keeps track of the number of references currently pointing to that object as soon as (and exactly whenthis counter drops to zerothe object' memory space is automatically reclaimed in the preceding listingwe're assuming that each time is assigned to new objectthe prior object' reference counter drops to zerocausing it to be reclaimed the most immediately tangible benefit of garbage collection is that it means you can use objects liberally without ever needing to allocate or free up space in your script python will clean up unused space for you as your program runs in practicethis eliminates substantial amount of bookkeeping code required in lower-level languages such as and +more on python garbage collection technically speakingpython' garbage collection is based mainly upon reference countersas described herehoweverit also has component that detects and reclaims objects with cyclic references in time this component can be disabled if you're sure that your code doesn' create cyclesbut it is enabled by default circular references are classic issue in reference count garbage collectors because references are implemented as pointersit' possible for an object to reference itselfor reference another object that does for exampleexercise at the end of part and its solution in appendix show how to create cycle easily by embedding reference to list within itself ( append( )the same phenomenon can occur for assignments to attributes of objects created from user-defined classes though relatively rarebecause the reference counts for such objects never drop to zerothey must be treated specially for more details on python' cycle detectorsee the documentation for the gc module in python' library manual the best news here is that garbage-collection-based memory management is implemented for you in pythonby people highly skilled at the task the case of the missing declaration statements