Skip to content

Commit 2ffc322

Browse files
committed
docs(leak-probe): note gesture recognizer cycles are missed before iOS 26
Before iOS 26, UIGestureEnvironment retains every recognizer attached to a view from its _nodesByGestureRecognizer NSMapTable, and the environment is reachable from a GC root, so a view -> recognizer -> JS state -> view cycle is held from outside and findLeakCycles cannot report it, even in strict mode. Measured on iOS 18.5 (recognizer retainCount 3, one found reference) against iOS 26.3 (retainCount 1, three unretained references from the Gestures node shim). Document that, and that NSHashTable, NSMapTable and NSPointerArray contents are not read, and expect the gesture cycle in strict reports only from iOS 26.
1 parent 1dd20d4 commit 2ffc322

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎TestRunner/app/tests/WrapperLifetimeLeaksTests.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ describe("Wrapper lifetime leak cycles", function () {
88
// A plain recognizer's JS state outlives its wrapper only when every
99
// wrapper is in scope; otherwise the edge back to its view dies with it.
1010
var gestureCycle = (rooted || canary) && runtime.getConfig("wrapperLifetimeScope") === "all";
11+
// Before iOS 26, UIKit's gesture environment retains a view's recognizers
12+
// while they are attached: a root holds that cycle, so no report names it.
13+
var gestureCycleReported =
14+
gestureCycle && NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion({ majorVersion: 26, minorVersion: 0, patchVersion: 0 });
1115

1216
// One class per shape, so a report names the shape.
1317
function shape(name) {
@@ -415,13 +419,13 @@ describe("Wrapper lifetime leak cycles", function () {
415419
expect(reports.inspect.cycles.length).toBe(reports.default.cycles.length);
416420
});
417421

418-
// UIKit's unretained pointers back to a recognizer read as more owners
419-
// than its retain count admits, so by default it counts as owned from
420-
// outside.
422+
// From iOS 26, UIKit's unretained pointers back to a recognizer read as
423+
// more owners than its retain count admits, so by default it counts as
424+
// owned from outside.
421425
it("reports a cycle through a view's gesture recognizer only when strict, marked uncertain", function () {
422426
expect(cyclesNaming(reports.default, "TNSLeakGestureView").length).toBe(0);
423427
var found = cyclesNaming(reports.strict, "TNSLeakGestureView");
424-
expect(found.length > 0).toBe(gestureCycle);
428+
expect(found.length > 0).toBe(gestureCycleReported);
425429
found.forEach(function (cycle) {
426430
expect(cycle.uncertain).toBe(true);
427431
expect(cycle.reasons.join("\n")).toMatch(/UITapGestureRecognizer 0x[0-9a-f]+: retainCount/);

‎docs/ns-builtin-modules.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,15 @@ missed rather than misreported:
257257
- objects the runtime does not retain whose class overrides `-retainCount`
258258
(CF-bridged classes, Swift and dispatch objects, among others; `CALayer`'s
259259
count is read from its ivars): another thread could free them while the
260-
probe calls it.
260+
probe calls it;
261+
- the contents of `NSHashTable`, `NSMapTable` and `NSPointerArray`, whose
262+
storage may be weak: what they retain counts as owned from outside.
263+
264+
Some leaks are held from a root rather than by a cycle alone, and are not
265+
reported even when strict. Before iOS 26, UIKit's gesture environment retains
266+
every recognizer attached to a view (in an `NSMapTable`), so a cycle through a
267+
view's gesture recognizer and its JS state is missed: seen on iOS 18.5, while
268+
iOS 26.3 reports it.
261269

262270
When the framework is embedded, in debug builds or with
263271
`"wrapperLifetime": { "leakProbe": true }` in the app config, the main isolate

‎types/ns-runtime.d.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ declare module "ns:runtime" {
277277
* reaches their owner in every mode. Slow (a full snapshot plus a native
278278
* object graph walk); meant for diagnostics, not production paths.
279279
*
280+
* What it cannot read counts as owned from outside, so those cycles are
281+
* missed rather than misreported: among others, the contents of
282+
* `NSHashTable`, `NSMapTable` and `NSPointerArray`. Before iOS 26, UIKit's
283+
* gesture environment retains every recognizer attached to a view, so a
284+
* cycle through a view's gesture recognizer is not reported, even when
285+
* strict (seen on iOS 18.5; iOS 26.3 reports it).
286+
*
280287
* @throws {Error} When the app does not embed `NativeScriptLeakProbe.framework`,
281288
* which app templates embed in debug builds only; list it in
282289
* `NS_SHIP_DEBUG_FRAMEWORKS` to ship it in other builds.

0 commit comments

Comments
 (0)