next up previous contents index
Next: Analysing Terms via the Up: Atoms and functors Previous: Atoms and functors   Contents   Index


Atoms and atom-garbage collection

With the introduction of atom-garbage collection in version 3.3.0, atoms no longer have live as long as the process. Instead, their lifetime is guaranteed only as long as they are referenced. In the single-threaded version, atom garbage collections are only invoked at the call-port. In the multi-threaded version (see threads, they appear asynchronously, except for the invoking thread.

For dealing with atom garbage collection, two additional functions are provided:

voidPL_register_atomatom_t atom Increment the reference count of the atom by one. PL_new_atom performs this automatically, returning an atom with a reference count of at least one.3.2 voidPL_unregister_atomatom_t atom Decrement the reference count of the atom. If the reference-count drops below zero, an assertion error is raised.

Please note that the following two calls are different with respect to atom garbage collection:


\begin{code}
PL_unify_atom_chars(t, ''text'');
PL_unify_atom(t, PL_new_atom(''text''));
\end{code}

The latter increments the reference count of the atom text, which effectively ensures the atom will never be collected. It is adviced to use the *_chars() or *_nchars() functions whenever applicable.


next up previous contents index
Next: Analysing Terms via the Up: Atoms and functors Previous: Atoms and functors   Contents   Index
Dr. Richard Botting 2001-12-12