1

Memory management is being done manually, ARC is not used in this project..

The message object is created using alloc init and the code below is being called on background thread.

I pass a message object before the following call:

 [self performSelectorOnMainThread:@selector(serverConnectionResult:) withObject: message waitUntilDone:NO];  

After the call I want to do:

 [message release];

I am confused whether I should do this, because I am concerned whether the message object will be always valid when serverConnectionResult is called? Is the method call performSelectorOnMainThread retaining the message object itself? What's the rule to know that the called method retains my passed object?

4

2 回答 2

2

这样做是安全的。-performSelectorOnMainThread:withObject:waitUntilDone:将保留消息的目标和对象。同样-performSelector:withObject:afterDelay:也会保留目标和对象。

于 2013-04-24T00:46:33.463 回答
0

You could also use Grand Central Dispatch and use dispatch_async on the main thread and pass in a block that calls your method and afterwards releases the message.

于 2013-04-24T01:17:29.450 回答