I know that in general handling Rc cycles is horrible, but I have a small special case I hoped might be solvable - - my cycles are always size 2, and each object can only be in one cycle.

I have a mathematical object with a method "inverse()" which for each value X returns the inverse of X. This is fairly expensive, so I keep I put it in an Rc and both return it and keep a clone inside X in case it is wanted again in future.

However, the inverse of the inverse of X is X, so I'd like to tell the new inverse object that its inverse is X (which will require X always being in an Rc, but I'm fine with that).

Therefore, during drop I could check if (a) there is only one strong reference left to X and (b) I have a stored inverse and (c) the stored inverse also only has one reference. If all these things are true, I have a tiny cycle and I should break the cycle so the two Rcs will free themselves.

My worry is if in future I upgrade to Arcs and start doing multitbreading, this kind of counting could break horribly. I don't suppose this kind of small fixed cycle has already been done well, by someone else?