ffi_leak_tracker 0.1.0 copy "ffi_leak_tracker: ^0.1.0" to clipboard
ffi_leak_tracker: ^0.1.0 copied to clipboard

Allocation tracking and leak detection for Dart FFI code.

Package: ffi_leak_tracker Publisher: halildurmus.dev Language: Dart License: BSD-3-Clause

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.

1
likes
160
points
--
downloads

Publisher

verified publisherhalildurmus.dev

Weekly Downloads

Allocation tracking and leak detection for Dart FFI code.

Repository (GitHub)
View/report issues
Contributing

Topics

#interop #ffi

Documentation

Documentation
API reference

Funding

Consider supporting this project:

github.com

License

BSD-3-Clause (license)

Dependencies

ffi

More

Packages that depend on ffi_leak_tracker