/* Global Setup and Tear Down hooks */ void setup_hook() { gc = gc_create(sizeof(object_type)); /* make this a root to the garbage collector */ gc_register_root(gc, &hash); gc_register_root(gc, (void **)&key1); gc_register_root(gc, (void **)&value); }
int main(int argc, char** argv) { GarbageCollector gc = gc_create(10,sizeof(struct node),node_mark,NULL,NULL); Node head = NULL; gc_protect(gc,&head); /* protect the list from garbage collection */ /* populate the list */ head = node(gc,head,1); head = node(gc,head,2); head = node(gc,head,3); /* force collect */ gc_collect(gc); /* check whether list still exists */ Node cur; for (cur = head; cur ; cur = cur->next) printf("%d\n",cur->value); gc_free(&gc); return 0; }