Load and destroy methods revised for proper reference counting
The update enhances object management by involving scope-based reference counting. The change affects loading and destruction operations in the Object and several other classes, ensuring the release or retention of objects adhere to their usage context. A function for logging type data has also been introduced to provide better clarity during debugging. Also, tests in script & interpreter have been altered to run in separate module initializations to avoid cross-test interference. Overall, it provides better memory management and dependable tests.
This commit is contained in:
parent
b06e1da529
commit
55571ca3dd
12 changed files with 58 additions and 10 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include "NewPlacement.hpp"
|
||||
#include "core/object.h"
|
||||
|
||||
#include "primitives/nullobject.h"
|
||||
|
||||
#include "HeapAllocatorGlobal.hpp"
|
||||
|
||||
#include <malloc.h>
|
||||
|
|
@ -63,6 +65,27 @@ namespace obj {
|
|||
tp::HeapAllocGlobal::deallocate(memh);
|
||||
}
|
||||
|
||||
void logTypeData(const ObjectType* type) {
|
||||
printf("type - %s\n", type->name);
|
||||
if (type->base) {
|
||||
printf("Based on ");
|
||||
logTypeData(type->base);
|
||||
}
|
||||
}
|
||||
|
||||
void assertNoLeaks() {
|
||||
if (bottom) {
|
||||
printf("ERROR : not all objects are destroyed\n");
|
||||
tp::ualni idx = 0;
|
||||
for (ObjectMemHead* memh = bottom; memh; memh = memh->up) {
|
||||
printf(" ===== Object - %i. Ref count - %i ===== \n", idx, memh->refc);
|
||||
logTypeData(NDO_FROM_MEMH(memh)->type);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct ObjectFileHead {
|
||||
Object* load_head_adress = 0;
|
||||
tp::halni refc = 0;
|
||||
|
|
@ -274,7 +297,13 @@ namespace obj {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
setrefc(out, ofh.refc);
|
||||
setrefc(out, 0);
|
||||
|
||||
// check for null object
|
||||
if (out->type == &NullObject::TypeData) {
|
||||
ObjectMemDeallocate(out);
|
||||
out = NdoNull_globalInstance;
|
||||
}
|
||||
|
||||
// save heap adress in "loaded_file"
|
||||
((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress = out;
|
||||
|
|
@ -405,8 +434,6 @@ namespace obj {
|
|||
}
|
||||
*/
|
||||
|
||||
setrefc(out, 0);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue