开发者

Do methods call retain on arguments when they get called?

开发者 https://www.devze.com 2023-03-05 04:20 出处:网络
If I call a method in Objective-C with an argument and releasing the argument afterwords. id argumentI = [Object new];

If I call a method in Objective-C with an argument and releasing the argument afterwords.

id argumentI = [Object new]; 
[ classA method1: argumentI ];
[ argumentI release ];

Then I know the argument is released AFTER method1 is finished, because the lines are processed linear. BUT when I call the method in a background thread:

[ NSThread detachNewThreadSelector:@selector(method1) toTarget:self withObject:argumentI ];
[ argumentI release ];

And then the main thread releases the object, WHILE the background job开发者_开发技巧 uses the argument for something (With the acceptance, that the retainCount would be 1 before the method is called). Could I get an Error, because of the use of a Zombie (use of an object, that is already deallocated)?

The question is:

Do the methods call retain on an object that is an argument? Or do I need to call retain at the beginning of the method, if it is like the problem above?


from the documentation of detachNewThreadSelector:toTarget:withObject:

The objects aTarget and anArgument are retained during the execution of the detached thread, then released.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号