diff --git a/Libraries/LibJS/Heap/Heap.cpp b/Libraries/LibJS/Heap/Heap.cpp index 4ad48b5a97..b3853680c4 100644 --- a/Libraries/LibJS/Heap/Heap.cpp +++ b/Libraries/LibJS/Heap/Heap.cpp @@ -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 roots; - gather_roots(roots); - mark_live_cells(roots); + if (collection_type == CollectionType::CollectGarbage) { + HashTable roots; + gather_roots(roots); + mark_live_cells(roots); + } sweep_dead_cells(); } diff --git a/Libraries/LibJS/Heap/Heap.h b/Libraries/LibJS/Heap/Heap.h index 53ec59d225..8ed4d55b87 100644 --- a/Libraries/LibJS/Heap/Heap.h +++ b/Libraries/LibJS/Heap/Heap.h @@ -53,7 +53,12 @@ public: return static_cast(memory); } - void collect_garbage(); + enum class CollectionType { + CollectGarbage, + CollectEverything, + }; + + void collect_garbage(CollectionType = CollectionType::CollectGarbage); Interpreter& interpreter() { return m_interpreter; } diff --git a/Userland/js.cpp b/Userland/js.cpp index 4c2cdc67f9..66e8316947 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -85,7 +85,5 @@ int main(int argc, char** argv) if (print_last_result) printf("%s\n", result.to_string().characters()); - dbg() << "Collecting garbage on exit..."; - interpreter.heap().collect_garbage(); return 0; }