Sometime during the day I thought of a really interesting way to encapsulate reference counting (if I'm understanding it correctly). The basic idea is that you have a structure similar to an element in a doubly-linked list - it has a pointer to the previous node, the next node, and a value. Now instead of any value, you have a pointer to a value. Whenever you make a new one of these structures (let's call them references) and set it to another reference, that new reference is added to the list. Whenever a reference has new data assigned to it, it takes itself out of the list and starts a new one. When a reference is destroyed, if both its reference pointers are NULL, it deletes the value.
While it would require more bytes of data to implement it, I was thinking that the advantage of using something like this would be that it could be used generically, rather than integrated into a specific data type.
Removal of a reference from the list wouldn't require any searching, it would just assign the previous node's next value its next value, and the next value's previous value its previous value.
I did something sort of similar to this to (try to) implement a robust mutex system (it wasn't quite the same as a mutex because it could use mutual exclusion or reference counting, but I can't remember the word for that). I don't remember if it worked or not.