reference counts within the state of every python object is an integer known as its reference count this is the count of how many references to the object exist anywhere in the system every time reference is assigned to this objectits reference count is incrementedand every time one of those references is reassigned to something elsethe reference count for the former object is decremented the maintenance of reference count for each object adds ( space per objectand the increments and decrements to the count add ( additional computation time per such operations the python interpreter allows running program to examine an object' reference count within the sys module there is function named getrefcount that returns an integer equal to the reference count for the object sent as parameter it is worth noting that because the formal parameter of that function is assigned to the actual parameter sent by the callerthere is temporarily one additional reference to that object in the local namespace of the function at the time the count is reported the advantage of having reference count for each object is that if an object' count is ever decremented to zerothat object cannot possibly be live object and therefore the system can immediately deallocate the object (or place it in queue of objects that are ready to be deallocatedcycle detection although it is clear that an object with reference count of zero cannot be live objectit is important to recognize that an object with nonzero reference count need not qualify as live there may exist group of objects that have references to each othereven though none of those objects are reachable from root object for examplea running python program may have an identifierdatathat is reference to sequence implemented using doubly linked list in this casethe list referenced by data is root objectthe header and trailer nodes that are stored as attributes of the list are live objectsas are all the intermediate nodes of the list that are indirectly referenced and all the elements that are referenced as elements of those nodes if the identifierdatawere to go out of scopeor to be reassigned to some other objectthe reference count for the list instance may go to zero and be garbage collectedbut the reference counts for all of the nodes would remain nonzerostopping them from being garbage collected by the simple rule above every so oftenin particular when the available space in the memory heap is becoming scarcethe python interpreter uses more advanced form of garbage collection to reclaim objects that are unreachabledespite their nonzero reference counts there are different algorithms for implementing cycle detection (the mechanics of garbage collection in python are abstracted in the gc moduleand may vary depending on the implementation of the interpreter classic algorithm for garbage collection is the mark-sweep algorithmwhich we next discuss