Track memory during deallocation correctly.
It used to subtract the number of bytes during deallocation, but that required knowing the size of an object at free time. That isn't always available. The old code could read a freed object while doing this. Bad! Instead, this tracks how much memory is still being used by marked objects. It's correct, and is also a bit less code and faster.
This commit is contained in:
+6
-2
@@ -212,8 +212,12 @@ struct WrenVM
|
||||
|
||||
// Memory management data:
|
||||
|
||||
// How many bytes of object data have been allocated so far.
|
||||
size_t totalAllocated;
|
||||
// TODO(bob): Temp.
|
||||
// The number of bytes that are known to be currently allocated. Includes all
|
||||
// memory that was proven live after the last GC, as well as any new bytes
|
||||
// that were allocated since then. Does *not* include bytes for objects that
|
||||
// were freed since the last GC.
|
||||
size_t bytesAllocated;
|
||||
|
||||
// The number of total allocated bytes that will trigger the next GC.
|
||||
size_t nextGC;
|
||||
|
||||
Reference in New Issue
Block a user