When should retain
be used ? I understand that it increments the object references count, so basicly the next release
on that object will not call dealloc
on it. Ok great, so what ? I read around that it's some kind of convention, that if you care about an object, you retain
it. Is there any examples of that out there ? Is that even true ?
EDIT:
I'm not looking for when the debugger tells you to do that or this. So, I looked into this.
To put it in my words, here's an example of a retain
usage
- in your code, you somewhere invoke a method a method that returns an object that you don't own
- you work with that object
- then you want to release it => you can't because you're not the owner
- your solution is to either use
copy
orretain
. If you userretain
, then you would get ownership of that object. - then to release that object, you either perform 2
release
(since ref count is 1+1 when you retain) or directly usedealloc
on it
Is that it ? I don't think so because an object can have multiple owner. So for the last point, calling dealloc
will really "kill" the object ; but with 2 release
, you won't be owner, but the program that created it would still be, therefore the objects is stil alive somewhere (leak ? zombie ?)
Please I'm confused.