I was reading through Apple’s doc of Basic Memory Management Rules. I came across a sentence, which is “Any object may have one or more owners.”
What does this mean? An object having 2 owners.
I am not really familiar with the OOP concepts.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In memory management, if an object owns a reference to another object it retains it.
Multiple objects can retain an object and when there are no retains on the object, no one owns it and it goes away. A retain increases a reference count and a release decrements it.
A good analogy is adding a leash to a pet. Multiple folks can add a leash but if no one has a leash on it, it can go away 🙂
If you are going to use a reference to an object outside of the immediate function that you are getting the reference, then you should retain it. If you call alloc, copy, mutableCopy to get the reference then you just retained it. If you get it by another message name, the standard is it’s autoreleased (which is fine) and will go away at some near point in the future outside the scope of that function.