dispose method

void dispose()

Releases native resources held by this configuration.

Safe to call multiple times -- subsequent calls are no-ops.

Also detaches this object's finalizer, so the safety net cannot release it a second time.

Throws StateError if the config has been consumed by Session.open or Zenoh.scout. This asymmetry with ZBytes.dispose (which no-ops on a consumed payload) is deliberate and pinned by test: disposing a config you already handed to the session is a caller bug worth reporting, and a config is consumed once per session rather than once per message. The consumed config's memory is already fully released by markConsumed, so this throw costs nothing.

Implementation

void dispose() {
  if (_disposed) return;
  _ensureNotConsumed();
  _disposed = true;
  // Detach BEFORE releasing, and after the guard above: a dispose that
  // throws because the config was consumed must not take the net down, and
  // on that path `markConsumed` has already detached anyway.
  configFinalizer.detach(this);
  bindings.zd_config_drop(_ptr.cast());
  calloc.free(_ptr);
}