It's clear that input
is a pointer. You have declared its type in the argument list as NSNumber*
.
input
is a pointer to an object of type NSNumber
. Internally, the object has an integer variable that holds the number of external references to it. Sending the retain
message to an object will increment its reference count. Sending the release
message will decrement the count. Sending the autorelease
message will adds the object to the local autorelease pool which will keep track of autoreleased objects and sends the release
message to them next time it drains. An object with reference count of 1 that receives a release
message will get deallocated and its dealloc
method will get called. You should release all the resources you hold when you are deallocated.
When you are setting a property, you want to release the old value and make sure the new value is kept around as long as the object itself is alive. To make sure the new value is kept around, you increment its reference count by 1 by sending it the retain
message. To release the old object, you'll send it the release message. There's one subtle issue here. If the old value is the same as the new value, if you release the old value first and its retain count was 1, it'll get destroyed before you can increment it. That's why you should retain the new value before releasing the old one.