I got this image from Apple docs:
Sorry for this stupid question. Someone can give an explanation of this image?. My interpretation:
- We create an instance of an Object of class A.
- After [[ClassA alloc]init] the object has a retain count of 1.
- After this, we create an instance of ClassB and add him to Class A as an iVar ¿it is correct? Instantiation means a retain count of 1, and the relation of ownership (now A owns B) means an increment of 1 of the retain count. (1+1 = 2) Now B has a retain count of 2. ¿it is correct? Anynone?
alloc
ornew
orcopy
will return an object with a retain count of1
. Any call toretain
will increase the retain count by1
,release
will decrease the retain count by1
, andautorelease
will decrease the retain count next time the "current" pool is released (typically when the main thread is idle next). All other methods have no impact on the retain count at all — if they create an object it will be 1 but autoreleased to 0. If the retain count hits0
the object may be destroyed (this is not guaranteed. do not rely on it) – Abhi Beckert@property
definition defines it asstrong
orretain
then the value will be retained when it's stored in the property and released when it's removed from the property. If it'sweak
orassign
orunsafe_unretained
then it will not be retained. If a property just has aset
method but no@property
definition you need to check the documentation but usually it will behave the same asstrong
. – Abhi Beckert