LibJS: Always collect all garbage when destroying Heap

When the Heap is going down, it's our last chance to run destructors,
so add a separate collector mode where we simply skip over the marking
phase and go directly to sweeping. This causes everything to get swept
and all live cells get destroyed.

This way, valgrind reports 0 leaks on exit. :^)
This commit is contained in:
Andreas Kling 2020-03-23 14:11:19 +01:00
commit b2f005125d
Notes: sideshowbarker 2024-07-19 08:10:15 +09:00
3 changed files with 13 additions and 7 deletions

View file

@ -51,6 +51,7 @@ Heap::Heap(Interpreter& interpreter)
Heap::~Heap()
{
collect_garbage(CollectionType::CollectEverything);
}
Cell* Heap::allocate_cell(size_t size)
@ -72,11 +73,13 @@ Cell* Heap::allocate_cell(size_t size)
return cell;
}
void Heap::collect_garbage()
void Heap::collect_garbage(CollectionType collection_type)
{
HashTable<Cell*> roots;
gather_roots(roots);
mark_live_cells(roots);
if (collection_type == CollectionType::CollectGarbage) {
HashTable<Cell*> roots;
gather_roots(roots);
mark_live_cells(roots);
}
sweep_dead_cells();
}