Expand/Shrink

free

Definition: free(object addr)
-- or --
addr = free(object addr) -- via ffree(), see technicalia
Description: Free up a previously allocated block of memory by specifying the address of the start of the block, ie/eg as returned by allocate().
The addr parameter can also be a sequence of such atoms, which are released in turn.
It may also be NULL or contain NULLs, which is/are politely ignored.
pwa/p2js: Not supported
Comments: Use free() to recycle blocks of memory during execution. This reduces the chance of running out of memory or getting into excessive virtual memory swapping to disk. Do not reference a block of memory that has been freed, or attempt to free() it more than once. In some (/many/most) cases it may help to deliberately zero the variable passed to the addr parameter immediately after free() returns, as per the second invocation method above.

If a delete_routine() is in force for addr, then the call to free() behaves as a call to delete(). It is assumed that will re-invoke free(), but with the internal delete_routine field zeroed, and by that I mean that the routine passed to delete_routine() explicitly invokes free(), rather than that aspect being somehow automatic (and/or somehow avoiding a double-free error).

When a program terminates, all allocated memory is returned to the system. Strictly speaking it is not necessary to release "one-off" allocations, and many legacy programs will not, however they may appear in the final report should memory leak checking be enabled (see technicalia).
Example: demo\rosetta\Count_examples.exw
Implementation: Partly in builtins\pAlloc.e (an autoinclude), but mainly via :%pFree in builtins\VM\pHeap.e (also an autoinclude) - be warned however it is low-level complicated stuff that you do not need to know.
See Also: allocate
Expand/Shrink