What happens when you call -retain on an object many times? Is it OK to just release it once at when you're done using it?
consider the name "reference counting".
you must match each
when reference counting, your program may hold one or more references to an object. you add a reference by retaining the object. when you are done with the object, you forfeit the reference using
object lifetimes are also affected by autorelease pools; a convenience mechanism which reduces the number of manual retains/releases as well as reference counting complexity (in some cases). you should read up on autorelease and autorelease pools for a further understanding of this mechanism.
How many times you call this method(retain) that many times Memory is allocated To that Object .you can Get Through Retain Count How many times Object Is being Allocated. Its creates memory Issues. If the Object Retain Count Is zero Then That Particular Object IS Not Unavailable to be used for other. that to If your Retain 10times One Object if U release Once its not being released. retain Increased by 1 count And Release Decreased by 1. if object having retain count 0 that object is unavailable.
Always remember this three things.
1.) Whenever you pass a retain message to any object, its retain count increases by 1.
2.) And subsequently when you pass a release message to any object, its retain count decreases by 1.
3.) And whenever you are done with the object, always check that its retain count is 0.
Hence, the number of times you retain an object should always be equal to the number of times you release that object.
You can check apple documentation regarding memory management here.