Skip to main content

Practice · 4 of 4

Reference Counting by Hand

CHALLENGE
Difficulty: advanced+25 XP

A file-scope int rcs_alive = 0; is already in your editor. Implement rc_t *rc_create(void) (refs = 1, counter++), void rc_hold(rc_t *r) (refs++), void rc_release(rc_t *r) (refs--; when it reaches 0: counter--, free; NULL is a no-op), and int rc_refs(const rc_t *r).

Back to lesson: Practice: Ownership Contract Drills