Implemented garbage collection

As a whole, this is still tentative.
This commit is contained in:
2026-05-08 16:28:12 +10:00
parent be84a8dfe2
commit 6c055a0435
15 changed files with 267 additions and 80 deletions
+19 -7
View File
@@ -227,17 +227,29 @@ void Toy_private_incrementScopeRefCount(Toy_Scope* scope) {
}
void Toy_private_decrementScopeRefCount(Toy_Scope* scope) {
for (Toy_Scope* iter = scope; iter; iter = iter->next) {
Toy_Scope* iter = scope;
while (iter) {
iter->refCount--;
if (iter->refCount == 0 && iter->data != NULL) {
if (iter->refCount == 0) {
//free the scope entries when this scope is no longer needed
for (unsigned int i = 0; i < iter->capacity; i++) {
if (iter->data[i].psl > 0) {
Toy_freeString(&(iter->data[i].key));
Toy_freeValue(iter->data[i].value);
if (iter->data != NULL) {
for (unsigned int i = 0; i < iter->capacity; i++) {
if (iter->data[i].psl > 0) {
Toy_freeString(&(iter->data[i].key));
Toy_freeValue(iter->data[i].value);
}
}
free(iter->data);
}
free(iter->data);
//free the scope itself, fixing the iterator for the next loop
Toy_Scope* empty = iter;
iter = iter->next;
Toy_releaseBucketPartition((void*)empty);
}
else {
iter = iter->next;
}
}
}