Differentiate between reference counting and automatic garbage collection with respect to Python.
Advertisements
Advertisements
प्रश्न
Differentiate between reference counting and automatic garbage collection with respect to Python.
अंतर स्पष्ट करें
Advertisements
उत्तर
| 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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
