Reputation: 1846
Consider the following code - obviously non-ARC:
.
.
.
NSString* someValueToSend= [NSString alloc] initWithString@"Send me! Will I survive?"];
if([delegate respondsToSelector:@selector(giveMeYourString:)])
{
[delegate performSelector:@selector(giveMeYourString:) onThread:someOtherThread withObject:someValueToSend waitUntilDone:NO];
}
[someValueToSend release];
.
.
.
Depending on what else is going on in the application, the delegate may or may not get around to running that selector before someValueToSend is released. Does the "system" do a "courtesy" retain on the object?
If not, and I am in a situation where I cannot block, what is a good strategy for sending a value across the boundary without a leak? Autorelease?
I did find a reference elsewhere that said the object is retained, but I have not seen that in the documentation....
Any input appreciated.
Upvotes: 1
Views: 187
Reputation: 162722
Yes, the system will retain the object.
And, no, autorelease
can never be used to protect an object from being released across a thread boundary. Technically, it can in the synchronous case, but don't do that.
Upvotes: 3