Skip to content

4.0: grace period for bounded retention (W2) - #24

Open
DanielCech wants to merge 2 commits into
dc/feat/v4-configurationfrom
dc/feat/v4-grace-period
Open

DanielCech wants to merge 2 commits into
dc/feat/v4-configurationfrom
dc/feat/v4-grace-period

Conversation

@DanielCech

Copy link
Copy Markdown
Member

Stacked on #23. Step 3 of the 4.0.0 plan.

Why

The hardest part of the JustFlip proof of concept was telling a real leak from an object that merely went away late: a store whose task finished after the timeout under simulator load looked exactly like a leak. Finding out meant rerunning the test alone with a longer timeout.

What's new

An object still alive at the timeout is watched for a grace period (3 s by default):

  • Released in that time: a warning, and the test passes.
    App.InterestListStore was released after 3.2 sec, later than the 2 sec timeout. That's bounded retention, not a leak: something kept it alive for a while, e.g. a task, an animation or a delayed callback. If that's expected, raise the timeout.
    
  • Still alive: a leak, as before. The message adds "It was watched for another 3 sec after that."

Set it with .deallocationGracePeriod(_:) or withDeallocationConfiguration; .zero turns it off. Passing checks are as fast as before. Only real leaks take the timeout plus the grace period to report.

Also fixed: durations in messages used Duration.formatted, which depends on the locale (on a Czech machine: "3 sec, 250,0 ms … 2,0 sec"). They now read the same everywhere: "400 ms", "2 sec", "3.2 sec".

Tests

  • Swift Testing:
    • a late release is a warning;
    • a leak still fails after the grace period, and the message mentions it;
    • .zero turns the grace period off.
  • XCTest: a late release passes as a non-strict expected failure.
  • Core: the message wording and locale-independent durations.
  • macOS (both trait configurations) and the iOS simulator pass.

🤖 Generated with Claude Code

DanielCech and others added 2 commits October 3, 2026 21:18
An object still alive at the timeout is watched for a grace period (3 s by
default, .deallocationGracePeriod(_:)). Released in that time: a warning,
"released after 3.2 sec, later than the 2 sec timeout … bounded retention,
not a leak". Still alive: a leak, as before. .zero turns it off.

Durations in messages no longer depend on the locale.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant