nativeFree property
Pointer<NativeFinalizerFunction>
get
nativeFree
Returns a pointer to a native free function.
This function can be used to release memory allocated by allocate
from the native side. It can also be used as a finalization callback
passed to NativeFinalizer constructor or Pointer.atTypedList
method.
For example to automatically free native memory when the Dart object wrapping it is reclaimed by GC:
class Wrapper implements Finalizable {
static final finalizer = NativeFinalizer(malloc.nativeFree);
final Pointer<Uint8> data;
Wrapper() : data = malloc.allocate<Uint8>(length) {
finalizer.attach(this, data);
}
}
or to free native memory that is owned by a typed list:
malloc.allocate<Uint8>(n).asTypedList(n, finalizer: malloc.nativeFree)
Implementation
Pointer<NativeFinalizerFunction> get nativeFree =>
Platform.isWindows ? winCoTaskMemFreePointer : posixFreePointer;