ffi_leak_tracker 0.1.0
ffi_leak_tracker: ^0.1.0 copied to clipboard
Allocation tracking and leak detection for Dart FFI code.
Allocation tracking and leak detection for Dart FFI code.
🎯 Overview #
package:ffi_leak_tracker helps you find and diagnose native memory leaks in
Dart FFI code by tracking allocations made through its custom allocators.
When tracking is enabled, every allocation is recorded with its size, type, call stack, and timestamp. You can then assert that all memory has been freed, inspect live allocations programmatically, or emit diagnostic reports — making it easy to catch leaks in tests or narrow down where they originate in production.
The package is designed to have no impact on release performance. The adaptive
allocators (adaptiveCalloc(), adaptiveMalloc()) compile away to standard
calloc() and malloc() in release builds, so you can leave them in place
unconditionally.
The diagnostic allocators (diagnosticCalloc(), diagnosticMalloc()) are
available for cases where tracking must remain active regardless of build mode.
Tracking can be enabled globally or scoped to a zone, so you can isolate specific tests or benchmarks without affecting the rest of your application.
⚡ Quick Example #
import 'dart:ffi';
import 'package:ffi_leak_tracker/ffi_leak_tracker.dart';
void main() {
// Enable tracking only in debug/profile builds.
LeakTracker.enableInDebug();
print('Allocating memory without freeing it...');
final ptr = adaptiveCalloc<Int32>();
// Fix the leak by uncommenting:
// adaptiveCalloc.free(ptr);
print('Verifying for leaks...');
// In debug builds this throws if any allocations remain.
LeakTracker.verifyNoLeaksInDebug();
print('No leaks detected.');
}
📝 Documentation #
Full documentation is available at win32.pub/docs/advanced/leak-tracking.
🐞 Features and Bugs #
If you encounter bugs or need additional functionality, please file an issue.