mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:07:34 +00:00
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. :^)
This commit is contained in:
parent
c7b4b5fe00
commit
9aaf19f4de
2 changed files with 10 additions and 1 deletions
|
@ -58,8 +58,14 @@ Heap::~Heap()
|
||||||
|
|
||||||
Cell* Heap::allocate_cell(size_t size)
|
Cell* Heap::allocate_cell(size_t size)
|
||||||
{
|
{
|
||||||
if (should_collect_on_every_allocation())
|
if (should_collect_on_every_allocation()) {
|
||||||
collect_garbage();
|
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) {
|
for (auto& block : m_blocks) {
|
||||||
if (size > block->cell_size())
|
if (size > block->cell_size())
|
||||||
|
|
|
@ -78,6 +78,9 @@ private:
|
||||||
|
|
||||||
Cell* cell_from_possible_pointer(FlatPtr);
|
Cell* cell_from_possible_pointer(FlatPtr);
|
||||||
|
|
||||||
|
size_t m_max_allocations_between_gc { 10000 };
|
||||||
|
size_t m_allocations_since_last_gc { false };
|
||||||
|
|
||||||
bool m_should_collect_on_every_allocation { false };
|
bool m_should_collect_on_every_allocation { false };
|
||||||
|
|
||||||
Interpreter& m_interpreter;
|
Interpreter& m_interpreter;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue