Byte arrays and the garbage collector
Factor handbook » C library interface » Passing data between Factor and C

Prev:C value boxes
Next:Enumeration types


The Factor garbage collector can move byte arrays around, and it is only safe to pass byte arrays to C functions if the garbage collector will not run while C code still has a reference to the data.

In particular, a byte array can only be passed as a parameter if the the C function does not use the parameter after one of the following occurs:
the C function returns
the C function calls Factor code via a callback

Returning from C to Factor, as well as invoking Factor code via a callback, may trigger garbage collection, and if the function had stored a pointer to the byte array somewhere, this pointer may cease to be valid.

If this condition is not satisfied, Manual memory management must be used instead.

Warning
Failure to comply with these requirements can lead to crashes, data corruption, and security exploits.