Ownership โ
Parser โ
Owns: state/value stacks, token scratch, reuse-candidate list, included-range list. Borrows: allocator, Language tables. deinit frees the owned lists.
Tree โ
Owns: source byte copy, SubtreePool (nodes + child indices). Borrows: allocator, Language. copy() duplicates all owned storage with the tree's allocator. applyEdit mutates positions in place โ no ownership change.
Node โ
Owns nothing. Two words. Invalid after its tree's deinit (use-after-free if misused โ the test suite guards the boundary with explicit lifetimes, never with runtime checks, for speed).
TreeCursor โ
Owns: path stack. Borrows: tree. copy() duplicates the stack.
Query / QueryCursor โ
Query owns: node list, child/field lists, pattern list, capture names, predicate arg slices. QueryCursor owns: match list plus one owned capture slice per match. Both borrow the allocator (and the language, for matching).
Changed ranges โ
getChangedRanges returns a caller-owned slice; freeChangedRanges releases it. Either tree sharing the allocator may free it.
