RetainCount == BAD
retainCountis taboo, unreliable, unpredictable and should not be used at all. I do not use it anywhere in my code, but I saw it in one class, which I use in an interesting way.
I have a class that starts a thread that runs indefinitely until the thread is canceled. The trick is that the thread increases the number of deductions of the owner, in my case the class that created it. That way, even if I finish using this class, this instance will still depend if someone who runs my class also doesn't know how to close the stream. This is one solution, but this is what I found in the code.
- (oneway void)release
{
if (self.retainCount == 2)
{
[self quitDispatchThread];
}
[super release];
}
, , . , 2. , , , ( 2 1), , (quitDispatchThread , ).
...
keepCount, , ?
, retainCount, , . , keepCount - , , , , saveCount - ..
?
, . , . retain release autorelease , , , , .
, .
:: NSThread
, NSThread. - target, selector - , .
initWithTarget: : :
NSThread, .
- (id) initWithTarget: (id) : (SEL) : (id)
, , .
. .
. .
NSThread, .
, , . .
target . , .