Objective-C 和返回时自动释放
两种方法
- (id) myFirstMethod
{
NSObject* anObject = [[NSObject alloc] init];
[anObject autorelease];
return anObject;
}
- (id) mySecondMethod
{
NSObject* anObject = [[NSObject alloc] init];
return [anObject autorelease];
}
相同吗?
Are the two methods
- (id) myFirstMethod
{
NSObject* anObject = [[NSObject alloc] init];
[anObject autorelease];
return anObject;
}
- (id) mySecondMethod
{
NSObject* anObject = [[NSObject alloc] init];
return [anObject autorelease];
}
identical?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这两种方法是相同的。每当你编写一个嵌套函数或多行相同的代码时,编译后都是一样的。
Yes the both methods are identical. Whenever you write a nested function or same code in multiple lines, it is all the same after compilation.
你可以在回报中做一切事情:
You could do everything in the return:
是的,它们是相同的,但它们所做的只是导致编译器错误。
不允许
[anObject]
。并且NSObject anObject
也是无效语法。Yes they are identical, but all they do is to cause a compiler error.
[anObject]
is not allowed. AndNSObject anObject
is also invalid syntax.