void freeobj_callback()

in ext/liballocations/liballocations.c [45:64]


void freeobj_callback(VALUE tracepoint, void* data) {
    st_data_t count;

    rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(tracepoint);
    AllocationState *state = allocation_state_get_struct(state_const);

    VALUE klass = rb_tracearg_defined_class(trace_arg);

    if ( IS_SINGLETON(klass) ) return;

    if ( st_lookup(state->object_counts, (st_data_t) klass, &count) ) {
        if ( count > 0 && (count - 1) > 0 ) {
            st_insert(state->object_counts, (st_data_t) klass, count - 1);
        }
        /* Remove the entry if the count is now 0 */
        else {
            st_delete(state->object_counts, (st_data_t*) &klass, NULL);
        }
    }
}