Closed pumkinpal closed 2 months ago
Hi @pumkinpal
I ran into the same issue, and found out that I made a mistake writing the code in reallocate()
.
My mistake was to not nest the two if
s:
vm.bytesAllocated += newSize - oldSize;
if (newSize > oldSize) {
#ifdef DEBUG_STRESS_GC
collectGarbage();
#endif
}
if (vm.bytesAllocated > vm.nextGC) {
collectGarbage();
}
if (newSize == 0) {
But in the source, the second if
is nested inside the first if
. During the sweep phase, objects only get freed, so newSize
is 0
, which is never > oldSize
. Thus bytesAllocated
isn't even compared with nextGC
and the recursive call is not made.
Hope that helps 😊
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()
.