See: https://www.drdobbs.com/atomic-reference-counting-pointers/184401888 for an implementation of atomic reference counts (multithread-safe).