What this Python object lifecycle question tests
This is a Cracked-difficulty Python question that probes your understanding of object destruction, garbage collection, and the distinction between explicit deletion and finalization. It asks you to trace the execution of code involving the del statement and the __del__ dunder method to predict what gets printed.
To solve problems like this, you need to understand when objects are actually deallocated, how del affects reference counts, and whether __del__ is guaranteed to run immediately or deferred. Python's memory model here differs sharply from languages with deterministic destructors, and interviewers often use this gap to separate candidates who have merely read the docs from those who have reasoned through the behaviour.
- Reference counting and the
del statement - The
__del__ finalizer method and its timing guarantees - Garbage collection and cycle detection
- Edge cases: circular references, exceptions in
__del__