Question

Consider I am allocating an object. Please see the below image

enter image description here

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.

Was it helpful?

Solution

What retain actually does under the hood is:

  1. Take a global lock in the objc runtime
  2. Look up a hash table entry based on the pointer to the object being retained
  3. Increment a counter in that entry
  4. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top