ghostty_free function

  1. @Native<Void Function(Pointer<GhosttyAllocator>, Pointer<Uint8>, Size)>(ffi.Pointer<GhosttyAllocator>, ffi.Pointer<ffi.Uint8>, ffi.Size)>()
void ghostty_free(
  1. Pointer<GhosttyAllocator> allocator,
  2. Pointer<Uint8> ptr,
  3. int len
)

Free memory that was allocated by a libghostty-vt function.

Use this to free buffers returned by functions such as ghostty_formatter_format_alloc(). Pass the same allocator that was used for the allocation, or NULL if the default allocator was used.

On platforms where the library's internal allocator differs from the consumer's C runtime (e.g. Windows, where Zig's libc and MSVC's CRT maintain separate heaps), calling the standard C free() on memory allocated by the library causes undefined behavior. This function guarantees the correct allocator is used regardless of platform.

It is safe to pass a NULL pointer; the call is a no-op in that case.

@param allocator Pointer to the allocator that was used to allocate the memory, or NULL if the default allocator was used @param ptr Pointer to the memory to free (may be NULL) @param len Length of the allocation in bytes (must match the original allocation size)

@ingroup allocator

Implementation

@ffi.Native<
  ffi.Void Function(
    ffi.Pointer<GhosttyAllocator>,
    ffi.Pointer<ffi.Uint8>,
    ffi.Size,
  )
>()
external void ghostty_free(
  ffi.Pointer<GhosttyAllocator> allocator,
  ffi.Pointer<ffi.Uint8> ptr,
  int len,
);