Skip to content

fail to collect references in release build #259

@mgood7123

Description

@mgood7123

jump to #259 (comment)

i am unsure how to go about keeping roots alive as they get eligible for garbage collection immediately after creation

    ManagedObjState state;

    managed_obj_init(&state, MANAGED_OBJECT_DEFAULT_ARENA_SIZE);
    
    managed_obj_t p = managed_obj_make(&state, malloc(500));
    printf("p is %p\n", p);

    // managed_obj_describe(&state);

    printf("first collect, p should not be collected\n");
    managed_obj_collect(&state); // should not collect p

    printf("if p has been collected then we have not managed to track it correctly\n");
    p = (managed_obj_t) 0x6; // no longer referenced

    printf("second collect, p should be collected\n");
    managed_obj_collect(&state); // should collect the original pointer assigned to p

    printf("if p has NOT been collected then we have not managed to track it correctly\n");

    managed_obj_deinit(&state);

(i assume there would be more that needs to be done in my implementation (below) to correctly support the above tho i am unsure as to what would be needed)

first collect, p should not be collected

object 0x7ffbf7100000 with pointer 0x12ea080 is being freed.
Total Collection duration: 0 seconds, 0 milliseconds, 192 microseconds

if p has been collected then we have not managed to track it correctly

second collect, p should be collected

Total Collection duration: 0 seconds, 0 milliseconds, 70 microseconds

if p has NOT been collected then we have not managed to track it correctly

deinit
deinit - collect
Total Collection duration: 0 seconds, 0 milliseconds, 43 microseconds
deinit - shutdown

the complete .h and .c file is https://gist.github.com/mgood7123/8a25971c90faa61397701361a0dd8be5

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions