Daily iOS
Memory and ARC

Task and self capture

After moving to Swift Concurrency, your team is arguing about whether you always need [weak self] inside Task { }. When is it unnecessary, and in which Tasks is it required?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

A Task isn't a cycle unless self holds the Task; it only extends self's lifetime for the duration of the work, so weak isn't required. A long-running or infinite-stream Task keeps self alive after the screen closes and needs weak self, and if you store the Task handle in a property of self, that's a real cycle and weak is mandatory.

Share a question