I found a explanation for property retain and release with real life example as below, it is very easy to understand.
I want to know if someone can use similar story to explain for copy and assign.
I want to know if someone can use similar story to explain for copy and assign.
Imagine a room in the library that you can reserve for studying purposes. Initially, the room is empty and hence the lights are off. When you reserve the room, the librarian increases a counter to indicate the number of persons using the room. This is similar to creating an object using the alloc keyword.
When you leave the room, the librarian decreases the counter, and if the counter is now 0, this means that the room is no longer being used and the lights can thus be switched off. This is similar to using the release keyword to release an object.
There may be times when you have booked the room and are the only one in the room (hence, the counter is 1) until a friend of yours comes along. He may simply come and visit you and therefore doesn't register with the librarian. Hence, the coun-ter does not increase. Because he is just visiting you and hasn't booked the room, he has no rights to decide whether the lights should be switched off. This is similar to assigning an object to another variable without using the alloc keyword. In this case, if you leave the room (release), the lights will be switched off and your friend will have to leave.
Consider another situation in which you are using the room and another person also booked the room and shares it with you. In this case, the counter is now 2. If you leave the room, the counter goes down to 1, but the lights are still on because another person is in the room. This situation is similar when you create an object and assign it to another variable that uses the retain keyword. In such a situation, the object is released only when both objects release it.
Continuing with our analogy of the room in the library, imagine that you are about to sign out with the librarian when you realize that you have left your books in the room. You tell the librarian that you are done with the room and want to sign out now, but because you left your books in the room, you tell the librarian not to switch off the lights yet so that you can go back to get the books. At a later time, the librarian can switch off the lights at his or her own choosing. This is the behavior of autoreleased objects.