diff --git a/gc.c b/gc.c index c9bcad4..0e5fb74 100644 --- a/gc.c +++ b/gc.c @@ -4,7 +4,8 @@ #include "vm.h" void mark(struct garbageObject *obj) { - if (obj->mark) return; + if (obj->mark) + return; ++obj->mark; @@ -36,10 +37,8 @@ void sweep(struct virtualMachine *vm) { } } -int collect(struct virtualMachine *vm) { - int count = vm->refCount; +void collect(struct virtualMachine *vm) { markAll(vm); sweep(vm); - vm->refMax = vm->refCount * 2; - return count - vm->refCount; + vm->refMax = vm->refCount * 2 <= STACK_MAX ? vm->refCount * 2 : STACK_MAX; } diff --git a/gc.h b/gc.h index f2320dc..794afec 100644 --- a/gc.h +++ b/gc.h @@ -13,6 +13,6 @@ void markAll(struct virtualMachine *vm); void sweep(struct virtualMachine *vm); // Marks and Sweeps all references -int collect(struct virtualMachine *vm); +void collect(struct virtualMachine *vm); #endif /* GC_H */