Skip to content

Instantly share code, notes, and snippets.

@GZGavinZhao
Created September 2, 2022 01:11
Show Gist options
  • Save GZGavinZhao/e562b365ed7ce7a53cd1180d9fc2b418 to your computer and use it in GitHub Desktop.
Save GZGavinZhao/e562b365ed7ce7a53cd1180d9fc2b418 to your computer and use it in GitHub Desktop.
NativeFinalizer work around to free pointers in a guaranteed way without ANY native code
import 'dart:ffi';
import 'package:ffi/ffi.dart';
void main(List<String> arguments) {
print('Opening the executable...');
final lib = DynamicLibrary.executable();
print('Grabbing `free` function from myself...');
final free = lib.lookupFunction<Void Function(Pointer), void Function(Pointer)>('free');
const String test = "Hello World!";
final ptr = test.toNativeUtf8();
free(ptr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment