Differentiate between reference counting and automatic garbage collection with respect to Python.
Advertisements
Advertisements
Question
Differentiate between reference counting and automatic garbage collection with respect to Python.
Distinguish Between
Advertisements
Solution
| Basis of Difference | Reference Counting | Automatic Garbage Collection |
|---|---|---|
| Basis | Counts the number of references pointing to an object. | Runs according to allocation and de-allocation thresholds. |
| Object deletion | Object is reclaimed immediately when its reference count becomes zero. | Unreachable objects are reclaimed when the garbage collector runs. |
| Cyclic references | Cannot independently reclaim objects involved in a reference cycle. | Can detect and reclaim many cyclically referenced unreachable objects. |
| Execution | Continuous during program execution as references change. | A scheduled/background activity of Python's garbage collector. |
| Example | del x may reduce an object's reference count. |
A self-referencing list can be collected by the cyclic garbage collector. |
shaalaa.com
Is there an error in this question or solution?
