[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [LeakDetector](https://evolu.dev/docs/api-reference/common/LeakDetector) › LeakDetector

Defined in: [packages/common/src/LeakDetector.ts:26](https://github.com/evoluhq/evolu/blob/a18269a1b822c670b507c6a9b73b23eed32551fe/packages/common/src/LeakDetector.ts#L26)

Detects handles that are garbage-collected while still considered held.

A handle such as a Lease must be explicitly cleaned up. Nothing in JavaScript
enforces that, so a handle whose last reference is dropped without cleanup
leaks silently. Garbage collection proves the leak: once the handle is
unreachable, no code can ever clean it up. A LeakDetector observes collection
with `FinalizationRegistry` and warns when the collected handle was still
held — a proven leak with zero false positives, pointing at the tracking
site.

Detection is best-effort: garbage collection timing is not deterministic, so
a warning may come late or, in short-lived processes, never. It is a
development canary, not a guarantee. Production uses
[noopLeakDetector](https://evolu.dev/docs/api-reference/common/LeakDetector/variables/noopLeakDetector).

## Extended by

- [`TestLeakDetector`](https://evolu.dev/docs/api-reference/common/LeakDetector/interfaces/TestLeakDetector)

## Properties

<a id="track"></a>

### track

```ts
readonly track: (target: object, leak: Leak, unregisterToken: object) => void;
```

Defined in: [packages/common/src/LeakDetector.ts:35](https://github.com/evoluhq/evolu/blob/a18269a1b822c670b507c6a9b73b23eed32551fe/packages/common/src/LeakDetector.ts#L35)

Starts tracking `target` until [untrack](https://evolu.dev/docs/api-reference/common/LeakDetector/interfaces/LeakDetector#untrack) or
garbage collection.

When `target` is garbage-collected and [Leak.isLeaked](https://evolu.dev/docs/api-reference/common/LeakDetector/interfaces/Leak#isleaked) returns `true`,
the leak is reported with the stack captured at this call. The leak must
not reference `target`, or the target would never become unreachable.

### untrack

```ts
readonly untrack: (unregisterToken: object) => void;
```

Defined in: [packages/common/src/LeakDetector.ts:38](https://github.com/evoluhq/evolu/blob/a18269a1b822c670b507c6a9b73b23eed32551fe/packages/common/src/LeakDetector.ts#L38)

Stops tracking the target registered with `unregisterToken`.