diff --git a/include/picrin/gc.h b/include/picrin/gc.h index fc5a644d..4970196f 100644 --- a/include/picrin/gc.h +++ b/include/picrin/gc.h @@ -26,5 +26,6 @@ struct pic_heap { }; void init_heap(struct pic_heap *); +void finalize_heap(struct pic_heap *); #endif diff --git a/src/gc.c b/src/gc.c index 925ca161..027cba08 100644 --- a/src/gc.c +++ b/src/gc.c @@ -34,6 +34,18 @@ init_heap(struct pic_heap *heap) #endif } +void +finalize_heap(struct pic_heap *heap) +{ + struct heap_page *page; + + while (heap->pages) { + page = heap->pages; + heap->pages = heap->pages->next; + free(page); + } +} + static void gc_free(pic_state *, union header *); static void