Do you know what happens if I retain an autoreleased object ? Will it be released or does the retain wins ?
Do you know what happens if I retain an autoreleased object ? Will it be released or does the retain wins ?
The retain
"wins" but thinking of it that way is full of fail.
retain and release are merely mechanisms via which you increase or decrease the retain count of an object. Autorelease is simply a delayed release; no more, no less.
If you retain an autoreleased object you are increasing the retain count NOW while the retain count will be decreased LATER. This happens all the time; [NSString stringWithFormat: @"...."]
returns an autoreleased string that you retain
if you want it to stick around beyond [most typically] the current pass through the event loop.