Reference counted memory in C