Raylib memory ownership


Binary file and memory APIs use native pointers with explicit lengths. load-file-data returns a native allocation; load-file-data-bytes copies the exact byte count and releases it.

Allocating text APIs expose -raw words for native ownership. Their existing string-returning conveniences copy and release the native text automatically, even if decoding fails.
load-file-data ( fileName bytesRead -- uchar* )

load-file-data-bytes ( fileName -- bytes/f )

load-file-text-raw ( fileName -- char* )

load-utf8-raw ( codepoints length -- char* )

encode-data-base64-raw ( data dataLength outputLength -- char* )

text-replace-alloc-raw ( text search replacement -- char* )

text-replace-between-alloc-raw ( text begin end replacement -- char* )

text-insert-alloc-raw ( text insert position -- char* )


TextReplace, TextReplaceBetween, TextInsert, GetTextBetween, TextJoin, TextTo* and TextSplit use static storage in Raylib 6.0. Their copied Factor strings require no native release; do not free static Raylib pointers. LoadTextLines is different: release its original char** and count together with unload-text-lines.

Native file-loader callbacks must return mem-alloc-compatible foreign storage because Raylib's unloaders release their results. Factor-managed strings and byte arrays cannot transfer ownership to C.https://github.com/raysan5/raylib/blob/6.0/src/raylib.h