dispose method

void dispose()

Releases native resources held by this key expression.

This is a local release. For a key expression obtained from Session.declareKeyExpr, it frees this handle and leaves the session's registration in place until the session is closed — use Session.undeclareKeyExpr to unregister it.

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 this key expression has been undeclared: undeclare already released everything, so a later dispose is a bug rather than a no-op.

Implementation

void dispose() {
  _ensureNotUndeclared();
  if (_disposed) return;
  _disposed = true;
  // Detach BOTH shapes before releasing, and after the guard above: a
  // dispose that throws because this was undeclared must not take the net
  // down, and on that path `undeclareFrom` has already detached.
  _detachNet();
  if (_isOwned) {
    bindings.zd_keyexpr_drop(_kePtr.cast());
  } else {
    malloc.free(_nativeStr);
  }
  calloc.free(_kePtr);
}