Skip to content
pubscout

ffi_leak_tracker

0.1.2, released 7 months ago by halildurmus.dev

Tracks and detects native memory leaks in Dart FFI allocations.

$ flutter pub add ffi_leak_tracker
Source repository

What it does

It records every allocation made through its custom allocators, storing size, type, call stack, and timestamp. You can then assert that all memory has been freed or inspect live allocations programmatically.

AI-written summary of version 0.1.2, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Debugging FFI memory usage
  • Testing for leaks in unit or integration tests
  • Diagnosing production memory leaks in debug builds

Skip it when

  • When you need zero runtime overhead in release builds, although adaptive allocators compile away

Strengths

  • Zero overhead in release builds via adaptive allocators
  • Zone‑scoped tracking for isolated tests
  • Simple API with global or zone enable/disable

Weaknesses

  • Only tracks FFI allocations, not Dart heap allocations
  • Requires Dart SDK 3.10 or newer

Setup

Kind
FFI (native library)
Effort
Low
Code generation
No
Direct dependencies
1
import 'dart:ffi';
import 'package:ffi_leak_tracker/ffi_leak_tracker.dart';

void main() {
  LeakTracker.enableInDebug();
  final ptr = adaptiveCalloc<Int32>();
  LeakTracker.verifyNoLeaksInDebug();
}

Alternatives

Packages that do the same job and could replace ffi_leak_tracker.

  • jni

    Provides Dart/Flutter bindings to call native Java code via JNI.

  • hooks

    Dart API for the JSON-based protocol for package build and link hooks.

  • snowplow_tracker

    Flutter package for sending Snowplow analytics events on Android, iOS, and Web.

  • flutter_olm

    Builds the native Olm library for Android and iOS to be used via dart:ffi.

Works with

Packages commonly used together with ffi_leak_tracker: ones it builds on, ones built on it, and its own family.