Free v0.1.0

Source
Releases the block the string owns.

Package: Text

Signature

func Free(self);

Remarks

There are no destructors, so ownership is released by hand: every String this package returns has to be freed exactly once. The empty string holds a null block, and Memory::Free ignores null, which makes this safe to call on any String at all.

It leaves an empty string behind — Data is null and Length is 0 — so a second call is a no-op rather than a double free, and the value stays usable as the empty string.

What it cannot see is a block shared by two String values, which is what plain assignment produces. Freeing each of them is a double free; take a Clone when both have to be released.

Example

import Text::String;

func Main() -> int {
    var text = String::From("Rux");

    text.Free();
    text.IsEmpty(); // true
    text.Free();    // harmless -- there is nothing left to release
    return 0;
}

See also

  • String — the string type
  • Clone — take a copy that can be freed on its own
  • Memory::Free — the release this is built on