Skip to main content

Practice ยท 1 of 1

Prove the cycle collector works

Implement cycle_probe(): 1. Create two Node instances (class defined below has partner = None). 2. Wire the cycle: a.partner = b and b.partner = a. 3. Record partners_wired = a.partner is b and b.partner is a. 4. Drop your local references to BOTH nodes. 5. Run gc.collect() and capture its return value. 6. Return (collected, partners_wired). Grading asserts partners_wired is True AND collected >= 2 โ€” the two mutually-referencing nodes are only reclaimable by the cycle collector.

Difficulty: advanced

Back to lesson: Practice: Project: Internals Investigation