LeakTracker class final

A static utility for tracking native memory allocations and detecting leaks.

LeakTracker maintains a registry of live allocations made through TrackingAllocator instances (adaptiveCalloc, adaptiveMalloc, diagnosticCalloc, and diagnosticMalloc). Each allocation is recorded with its address, size, type, timestamp, and call stack, enabling precise diagnostics when memory is not freed as expected.

Constructors

LeakTracker()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

enabled bool
Whether leak tracking is currently enabled.
no setter
globalFilter LeakFilter
Global filter applied to all allocations unless overridden by a scoped execution zone.
getter/setter pair
hasLeaks bool
Whether any tracked allocations currently exist.
no setter
snapshot List<Allocation>
Returns a snapshot of currently tracked allocations.
no setter

Static Methods

addGlobalFilter(LeakFilter filter) → void
Adds filter to the global filter using logical OR composition.
clearGlobalFilter() → void
Clears the global filter, restoring default behavior.
disable() → void
Disables native memory leak tracking globally.
emit({LeaksEmitter emitter = const .print()}) → void
Emits a leak report using the provided emitter.
enable() → void
Enables tracking native memory allocations globally.
enableInDebug() → void
Enables tracking native memory allocations only in debug and profile builds.
reset() → void
Clears the current registry without freeing memory.
runScoped<R>(R body(), {LeakFilter? filter}) → R
Runs body inside an isolated tracking scope.
verifyNoLeaks() → void
Throws a LeakTrackerException if any leaks are currently tracked.
verifyNoLeaksInDebug() → void
Equivalent to verifyNoLeaks but only active in debug and profile builds.