As asked
An iOS screen is dismissed but its view model and network task never deallocate. How would you find and fix the retain cycle?
Sample answer outline
Start with the memory graph debugger or Instruments to identify the ownership chain keeping the object alive. Common causes are closures capturing self strongly, delegates not marked weak, Combine subscriptions retained by the same object they capture, and tasks that outlive the view lifecycle. The fix is not blindly adding weak self everywhere, but deciding which object owns the work and when cancellation should happen. A view model should usually cancel outstanding tasks in deinit or when the lifecycle ends. Strong candidates explain ARC as deterministic reference counting with cycles that need explicit weak or unowned links.
Expect these follow-ups
- When is unowned safe and when is it dangerous?
- How do async Task closures capture self?
- How would you test that a screen deallocates?