From a9f49b89a40cb5ccdac7185c57812c800654109a Mon Sep 17 00:00:00 2001 From: Will Speak Date: Sun, 9 Oct 2016 17:59:58 +0100 Subject: [PATCH] Fix Bug in GC Reallocation Calculation Updates the way we calculate thenext GC to make sure that we're not already past the threshold. This was causing endless garbage collections on 32 bit builds in `test/language/deeply_nested_gc.wren`. --- src/vm/wren_vm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/vm/wren_vm.c b/src/vm/wren_vm.c index 98cddbf4..26ddac0e 100644 --- a/src/vm/wren_vm.c +++ b/src/vm/wren_vm.c @@ -173,10 +173,9 @@ void wrenCollectGarbage(WrenVM* vm) } } - // +100 here because the configuration gives us the *additional* size of - // the heap relative to the in-use memory, while heapScalePercent is the - // *total* size of the heap relative to in-use. - vm->nextGC = vm->bytesAllocated * (100 + vm->config.heapGrowthPercent) / 100; + // Calculate the next gc point, this is the current allocation plus + // a configured percentage of the current allocation. + vm->nextGC = vm->bytesAllocated + ((vm->bytesAllocated * vm->config.heapGrowthPercent) / 100); if (vm->nextGC < vm->config.minHeapSize) vm->nextGC = vm->config.minHeapSize; #if WREN_DEBUG_TRACE_MEMORY || WREN_DEBUG_TRACE_GC