ffi_leak_tracker library
Allocation tracking and leak detection for Dart FFI code.
Provides allocators that record metadata — size, type, timestamp, and call stack — for every native allocation. Recorded allocations can be inspected programmatically, asserted to be leak-free, or emitted as diagnostic reports.
| Allocator | Zeroes memory | Release build |
|---|---|---|
adaptiveCalloc |
✓ | compile away to calloc |
adaptiveMalloc |
✗ | compile away to malloc |
diagnosticCalloc |
✓ | retains tracking |
diagnosticMalloc |
✗ | retains tracking |
Prefer the adaptive allocators in application code. Use the diagnostic variants only when tracking must remain active in release builds.
Classes
- AddressesFilter
- Ignores allocations whose address matches one of a set of values.
- Allocation
- Represents a recorded native memory allocation.
- AndFilter
- Logical AND combination of multiple filters.
- DiagnosticCallocAllocator
- A zero-initializing TrackingAllocator.
- DiagnosticMallocAllocator
- A non-zero-initializing TrackingAllocator.
- IgnoreAllFilter
- A filter that ignores all allocations.
- IgnoreNoneFilter
- A filter that ignores no allocations.
- JsonEmitter
- Emits leaks as a JSON file.
- LeakFilter
- Defines a rule that determines whether an Allocation should be ignored.
- LeaksEmitter
- Emits detected memory leaks to an output destination.
- LeakTracker
- A static utility for tracking native memory allocations and detecting leaks.
- NotFilter
- Logical negation of a filter.
- OrFilter
- Logical OR combination of multiple filters.
- PrintEmitter
- Emits leaks as a formatted console report.
- StackContainsFilter
- Ignores allocations whose stack trace contains a pattern.
- TrackingAllocator
- Base class for allocators that integrate with the leak tracker.
- TypesFilter
- Ignores allocations whose type matches one of a set of values.
Extensions
- AllocatorExtensions on Allocator
- Extends any Allocator with a nativeFree pointer.
Constants
- adaptiveCalloc → const Allocator
-
A zero-initializing allocator that compile away to
callocin release builds. - adaptiveMalloc → const Allocator
-
A non-zero-initializing allocator that compile away to
mallocin release builds. - diagnosticCalloc → const DiagnosticCallocAllocator
- A zero-initializing allocator that always retains leak-tracking capability.
- diagnosticMalloc → const DiagnosticMallocAllocator
- A non-zero-initializing allocator that always retains leak-tracking capability.
Exceptions / Errors
- LeakTrackerException
- Exception thrown when one or more memory leaks are detected.