Bird
0
0

Why might the __del__ method not be called for some Python objects?

hard📝 Conceptual Q10 of 15
Python - Classes and Object Lifecycle
Why might the __del__ method not be called for some Python objects?
ABecause of circular references preventing garbage collection
BBecause __del__ is called immediately on object creation
CBecause __del__ replaces __init__
DBecause Python does not support destructors
Step-by-Step Solution
Solution:
  1. Step 1: Understand __del__ and garbage collection

    __del__ is called when an object is garbage collected, but circular references can prevent collection.
  2. Step 2: Identify why __del__ might not run

    If objects reference each other in a cycle, Python's garbage collector may not immediately collect them, delaying or skipping __del__ calls.
  3. Final Answer:

    Because of circular references preventing garbage collection -> Option A
  4. Quick Check:

    Circular refs block __del__ = May not be called [OK]
Quick Trick: Circular references can delay or block __del__ calls [OK]
Common Mistakes:
  • Thinking __del__ runs on creation
  • Confusing __del__ with __init__
  • Believing Python lacks destructors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes