Free v0.1.0

Source
Releases a block of memory back to the platform.

Package: Memory

Signature

func Free(ptr: *opaque);

Parameters

NameTypeDescription
ptr*opaqueA block from Alloc or Realloc.

Remarks

Passing null is a no-op, so a caller needs no guard around the common "allocate, maybe fail, clean up" path.

Anything else is undefined behavior and is not diagnosed: releasing the same block twice, releasing a pointer that Realloc has already moved, or passing a pointer this package did not produce. After the call the block is gone and the pointer must not be read, written, or freed again.

Example

import Memory::{ Alloc, Free };

func Main() -> int {
    let buffer = Alloc(256);
    if buffer == null {
        return 1;
    }

    Free(buffer);
    Free(null); // harmless
    return 0;
}

See also

  • Memory — the package overview
  • Alloc — allocate the block in the first place
  • Realloc — resize a block instead of releasing it