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:
Bob Nystrom
2013-12-14 22:17:16 +00:00
parent 78f6e3b96d
commit 07c3dff92f
4 changed files with 124 additions and 124 deletions
+1 -1
View File
@@ -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;