I am going to interpret this as simple as possible if I do not answer your question, I apologize.
When you really get the answer to this question, this is your first step towards really thinking about the object-oriented level.
In OO, when two objects have an "object" zero, itโs quite acceptable for both references to this other object. The trick with OO is that the objects have their own life, they are fluid, and anyone who needs them can reference them. The object must remain "Valid" and maintain stability when used by many other objects. (That's why immutable objects such as String are so large they are ALWAYS valid, like the second they were created)
The only exception is if you are coding in C ++, because then you really need to manually free objects, which implies an owner who can control every life cycle of the object, which makes it really "difficult" to think in OO in C ++ .
[Addition] Since you are referencing pointers, I think you are programming in C ++, which is different. In this case, you are right. Make one Native manager the life cycle of your shared asset. It should not let this object die until all other links have disappeared.
You can also use reference counting. Whenever someone gets a reference to your object, he calls "addReference" or something like that, whenever this is done, the link is deleted. If someone calls removeReference when the counter is 1, the object can clear itself. This is probably so close that you can come to the true distribution / deallocation of OO-style in C ++. This is very error prone.
There are libraries that I believe do such things.
source share