You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've observed that collectGarbage() can be called recursively during the sweep phase as freeing objects calls reallocate() while vm.bytesAllocated is still greater than vm.nextGC, which is only updated after the sweep phase ends.
Updating vm.nextGC before calling markRoots() in collectGarbage() seems to solve this issue as it ensures that vm.nextGC won't be less than vm.bytesAllocated throughout the sweep, preventing reallocate() from calling collectGarbage().
void collectGarbage()
{
#ifdef CLOX_DEBUG_LOG_GC
printf("-- gc begin\n");
size_t before = vm.bytesAllocated;
#endif
// Update nextGC before mark and sweep to ensure GC isn't re-triggered by freeing memory
vm.nextGC = vm.bytesAllocated;
markRoots();
traceReferences();
tableRemoveWhite(&vm.strings);
sweep();
vm.nextGC = vm.bytesAllocated * CLOX_GC_HEAP_GROW_FACTOR;
#ifdef CLOX_DEBUG_LOG_GC
printf("-- gc end\n");
printf(" collected %zu bytes (from %zu to %zu) next at %zu\n",
before - vm.bytesAllocated, before, vm.bytesAllocated,
vm.nextGC);
#endif
}
The text was updated successfully, but these errors were encountered:
I've observed that
collectGarbage()
can be called recursively during the sweep phase as freeing objects callsreallocate()
whilevm.bytesAllocated
is still greater thanvm.nextGC
, which is only updated after the sweep phase ends.Updating
vm.nextGC
before callingmarkRoots()
incollectGarbage()
seems to solve this issue as it ensures thatvm.nextGC
won't be less thanvm.bytesAllocated
throughout the sweep, preventingreallocate()
from callingcollectGarbage()
.The text was updated successfully, but these errors were encountered: