mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
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:
parent
6dc4b23e2f
commit
b2f005125d
3 changed files with 13 additions and 7 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue