C Collections

cyaml · Section 3

cyaml_destroy

cyaml_destroy - recursively free a DOM tree and null the handle

C Collections (libccollections, -lccollections)

#include <ccollections/cyaml.h>
 
cyaml_destroy(node);

When node is not NULL, the macro frees the whole DOM subtree under
node, each node with the allocator that it stores, and then sets
node to NULL.
 
Everything below node goes: The children of each list, the values of
each dictionary and the string copies.  Destroying the same handle a
second time is safe, because the variable is NULL after the first
destroy.
 
That is also why node must be an assignable lvalue.  You cannot pass
a plain NULL literal or any other expression that is not an lvalue.

node  The cyaml variable to destroy.  The macro sets the variable
      itself to NULL.

The macro evaluates node exactly once, so an expression with a side
effect, such as handles[i++], destroys and clears one element.  node
must be a modifiable lvalue, such as a variable or an array element.

cyaml root = cyaml_parse("a: 1\n", NULL);
/* ... use root ... */
cyaml_destroy(root);   /* root is now NULL */

cyaml_declare_scoped(3)