Created
September 2, 2022 01:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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