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.

example/main.dart

// ignore_for_file: unused_local_variable

import 'dart:ffi';

import 'package:ffi_leak_tracker/ffi_leak_tracker.dart';

/// Basic example demonstrating how leak detection works.
///
/// Run this in debug mode to see the tracker report a leak.
/// Uncomment the `adaptiveCalloc.free(ptr)` code to resolve it.
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.');
}
1
likes
160
points
100
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