# Persistent pointer boundaries and reference-count cycles

A surviving pointer representation does not prove that its target is still
available. Check three separate questions: can the reference be resolved after
remapping, does the target belong to a permitted lifetime domain, and is the
target still owned?

## A small counterexample

This original synthetic graph example explains ownership only. Assume two
allocated objects, A and B, and exact strong-reference counts. Initially an
external root keeps A alive. The root is then removed.

| Internal links | External roots after removal | Objects retained by reference counts |
| --- | --- | --- |
| A strongly references B; B strongly references A | None | A and B |
| A strongly references B; B weakly references A | None | None |

In the first row, each object still has one incoming strong reference. Neither
reaches zero, even though neither is reachable from an external root. In the
second row, A reaches zero first; collecting it removes B's last strong
reference. Collection then reaches B.

A weak link is therefore an ownership decision, not a performance switch.
Making every link weak would also allow an intended target to die too early.
A retained object and an externally reachable object are different predicates.

Run the self-contained implementation and its tests with Node:

```sh
node --test model.test.mjs
```

The tests cover nine heap-domain pairs, invalid inputs, strong and weak cycles,
repeated references, weak-only targets, and all 1,024 combinations of forward
edges and root sets on four ordered nodes. For those acyclic graphs, a separately
implemented reachability traversal must agree with reference-count collection.
That bounded enumeration is a software check, not a distribution of real heaps.

## Relation to NV-Heaps

The [NV-Heaps record](https://hesela.dev/terms/nv-heaps/) describes the historical
design. The [author presentation, slides 18-22](https://www.sniadeveloper.org/sites/default/files/files2/files2/SDC2013/presentations/Revisions/JoelCoburn_NVHeaps_Revision.pdf)
separates relative addressing, checked references, reference counting and
transactions. The example isolates why weak references matter; it does not
implement the design's proxy invalidation, logs, allocator or locking.

The [ASPLOS 2011 paper](https://cseweb.ucsd.edu/~swanson/papers/Asplos2011NVHeaps.pdf)
is the primary source. Its evaluation scope must remain separate from this
example and from a real power-loss experiment.

## Limits and reproducibility

The model assumes an already constructed graph with exact counts and no concurrent
mutations. It has no bytes, flushes, torn writes, durable metadata, addresses,
restarts, timings or device measurements. Removing roots is not a simulation of
NV-Heaps process-exit recovery. The scope policy is checked independently from the
graph collector; it does not validate a real heap.

Files: [model.mjs](model.mjs), [model.test.mjs](model.test.mjs).
No dependencies, random seed or external input dataset are needed.
Authored 2026-12-05. Original example and prose: Hesela team.
