What is IOS retain do at backend [closed]

橙三吉。 提交于 2019-12-12 04:12:56

问题


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:

  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.



来源:https://stackoverflow.com/questions/12990128/what-is-ios-retain-do-at-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!