Skip to content

docs: align lifecycle KDoc with actual GC management#490

Merged
milyin merged 1 commit into
zenoh-flat-transitionfrom
gc-lifecycle-docs
Jul 17, 2026
Merged

docs: align lifecycle KDoc with actual GC management#490
milyin merged 1 commit into
zenoh-flat-transitionfrom
gc-lifecycle-docs

Conversation

@milyin

@milyin milyin commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What

Aligns the SDK lifecycle KDoc with the actual GC management, following an audit of every ptr_class against zenoh-flat-jni's .gc_managed() roster. With paired ZettaScaleLabs/zenoh-flat-jni#8 (Config joins), every handle-owning class except ZBytes is GC-backstopped when forgotten — and the docs now say exactly what happens to forgotten instances.

Fixes found by the audit:

  • Session.close() KDoc contradicted the code: it claimed declarations bound to the session "will still be alive" after close, but close() undeclares every strong and weak declaration. The doc now matches the behavior, and the class KDoc notes the GC backstop (explicit close recommended for deterministic release).
  • ZBytes gets the lifecycle section it was missing — the one class where GC will not save the user: created ZBytes are plain values (no native memory); received ones free their native buffer automatically on first read; a received payload/attachment that is never read keeps its native buffer (deliberate hot-path exclusion: per-message Cleaner registration measured −23% throughput @8B).
  • Publisher/Querier: the session reference is weak — a forgotten instance is undeclared by the GC backstop (the old text implied it waited for session close).
  • Subscriber/Queryable: the session reference is strong — dropping your reference does not stop the subscription/queryable; it stays active until undeclare/close or session close (zenoh semantics).
  • Scout/LivelinessToken: "automatically undeclared when dropped" now spelled out as GC-collected, non-deterministic; close for prompt effect.
  • KeyExpr (declared) and Config: short backstop notes (declared keyexprs are strong session declarations; a Config is consumed by open/scout, an unused one is GC-released).

Doc-only on the Kotlin side; CI pin points at flat-jni#8's branch tip dbb1f8c (bump to the merge commit after it lands).

Tests

113 jvmTest, 0 failures (composite build against the pinned flat-jni).

🤖 Generated with Claude Code

Every handle-owning class except ZBytes is now GC-backstopped (Config
joined in zenoh-flat-jni PR#8), and the docs now say exactly what
happens to forgotten instances:

- Session: close() KDoc contradicted the code — close undeclares every
  live declaration, it does not leave them alive; class KDoc notes the
  GC backstop.
- ZBytes: new lifecycle section — created ZBytes are plain values;
  received ones free their native buffer on first read; a received
  payload/attachment that is never read keeps it (deliberately NOT
  GC-managed: per-message Cleaner cost measured -23% thr @8B).
- Publisher/Querier: session reference is weak — forgotten instances
  are undeclared by the GC backstop, not at session close only.
- Subscriber/Queryable: session reference is strong — dropping the
  reference does NOT stop them; active until undeclare or session
  close.
- Scout/LivelinessToken: 'dropped' now spelled out as GC-collected,
  non-deterministic; close for prompt effect.
- KeyExpr (declared) / Config: backstop notes.

CI pin bumped to flat-jni dbb1f8c (Config gc_managed, PR#8).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@milyin
milyin merged commit 2ae6e67 into zenoh-flat-transition Jul 17, 2026
13 checks passed
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