summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Heap/Heap.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-06 12:36:49 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-06 15:54:46 +0200
commit9aaf19f4de1ba1f1bd7278f35d5b3c9e56d860da (patch)
treebf0e3cb2e74e831584e984d52cd7cc58744a35f5 /Libraries/LibJS/Heap/Heap.cpp
parentc7b4b5fe001136d13331d4a9aa63b4b43d20c452 (diff)
downloadserenity-9aaf19f4de1ba1f1bd7278f35d5b3c9e56d860da.zip
LibJS: Do a garbage collection every N allocations (N=10'000)
To prevent the heap from growing infinitely large, we now do a full GC every 10'000 allocations. :^)
Diffstat (limited to 'Libraries/LibJS/Heap/Heap.cpp')
-rw-r--r--Libraries/LibJS/Heap/Heap.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Libraries/LibJS/Heap/Heap.cpp b/Libraries/LibJS/Heap/Heap.cpp
index c75702bd35..3dd3902ca5 100644
--- a/Libraries/LibJS/Heap/Heap.cpp
+++ b/Libraries/LibJS/Heap/Heap.cpp
@@ -58,8 +58,14 @@ Heap::~Heap()
Cell* Heap::allocate_cell(size_t size)
{
- if (should_collect_on_every_allocation())
+ if (should_collect_on_every_allocation()) {
collect_garbage();
+ } else if (m_allocations_since_last_gc > m_max_allocations_between_gc) {
+ m_allocations_since_last_gc = 0;
+ collect_garbage();
+ } else {
+ ++m_allocations_since_last_gc;
+ }
for (auto& block : m_blocks) {
if (size > block->cell_size())