Rules Hub
Code Ruleset
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
mobile ruleP1universalStack: mobile
mobilelifecyclecancellationmemory
Cancel in-flight requests/tasks when the screen goes away
Requests tied to a screen must be cancelled on teardown so callbacks don't fire into a dead view or waste bandwidth.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codeswift
| 1 | // task keeps running after the view controller is dismissed |
Explanation (EN)
Work retaining a departed screen can waste resources or update an obsolete view.
Objašnjenje (HR)
Good example
New codeswift
| 1 | deinit { task?.cancel() } // or rely on structured concurrency scope |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Tie screen-owned work to the actual screen/task lifecycle and verify that the underlying API cooperatively cancels and releases retained callbacks.
Exceptions / Tradeoffs (EN)
A view controller can remain alive after dismissal; deinit is not always the correct screen-exit event. Work intended to survive navigation needs a separate owner.