I want to be able to call an object's method on a new thread; but, I am confused about how to manage retain counts (or even if it is an issue).
In a non-threaded scenario, I would do this:
MyObject *newObject = [[MyObject alloc] init];
[newObject doSomething];
[newObject release];
In this scenario, everything's fine. However, my question is whether the following threaded version is a problem:
MyObject *newObject = [[MyObject alloc] init];
[NSThread detachNewThreadSelector:@selector(doSomething)
toTarget:newObject
withObject:nil];
[newObject release];
In this case, do I have to worry about newObject
being released while -doSomething
is processing? If the answer is yes, then it seems messy to have -doSomething
retain self
.
Is this an issue? And, if so, what's the correct solution?