问题
Consider I am allocating an object. Please see the below image
In the above image *myObject is a pointer. It is referring to an space allocated to that object. When we retain the object, I like to know what it does at backend. Also I like to know why we are doing that.
Also when we release it how it works at backend.
I also like to know what happens at backend when we copy an object.
I am really sorry if my question is so basic.
回答1:
What retain actually does under the hood is:
- Take a global lock in the objc runtime
- Look up a hash table entry based on the pointer to the object being retained
- Increment a counter in that entry
- Release the lock
I don't expect this to be all that helpful in practice, but I think it's what you were asking for.
来源:https://stackoverflow.com/questions/12990128/what-is-ios-retain-do-at-backend