nativeFree property

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(calloc.nativeFree);

  final Pointer<Uint8> data;

  Wrapper() : data = calloc.allocate<Uint8>(length) {
    finalizer.attach(this, data);
  }
}

or to free native memory that is owned by a typed list:

calloc.allocate<Uint8>(n).asTypedList(n, finalizer: calloc.nativeFree)

Implementation

Pointer<NativeFinalizerFunction> get nativeFree =>
    Platform.isWindows ? winCoTaskMemFreePointer : posixFreePointer;