fix: track live memory via bytesAllocated instead of subtracting freed sizes
The old code subtracted oldSize from totalAllocated during deallocation, which required knowing the object size at free time. This was unsafe because it could read a freed object to determine its size. The new approach tracks bytesAllocated by only adding new allocations and relying on GC marking to account for freed memory, making it both correct and faster with less code.
This commit is contained in:
+1
-1
@@ -137,7 +137,7 @@ DEF_NATIVE(list_add)
|
||||
DEF_NATIVE(list_clear)
|
||||
{
|
||||
ObjList* list = AS_LIST(args[0]);
|
||||
wrenReallocate(vm, list->elements, list->capacity * sizeof(Value), 0);
|
||||
wrenReallocate(vm, list->elements, 0, 0);
|
||||
list->capacity = 0;
|
||||
list->count = 0;
|
||||
return NULL_VAL;
|
||||
|
||||
Reference in New Issue
Block a user