@property(retain)需要释放吗? [英] Does @property(retain) need a release?

查看:182
本文介绍了@property(retain)需要释放吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是代码的三个片段,前两个是两个对象的接口以及两个@property命令。请注意,这只是我学习,它不是应用程序的一部分只是一个小测试程序。

Below are three fragments of code, the first two are interfaces for two objects along with a couple of @property commands. Please note that this is just me learning, its not part of an application just a small test program.

添加(保留)到第二个@property后,我注意到我的程序退出时,我的机器对象泄漏,我修复这个问题是在艺术家对象dealloc,这听起来是否正确?

After adding (retain) to the 2nd @property I noticed that my machine object was leaking when my program exited, what I did to fix this was add a release in the Artist objects dealloc, does this sound right?

@interface Machine : NSObject
{
    NSString *name;
    NSString *type;
    NSString *os;
}

@interface Artist : NSObject
{
    NSString *name;
    Machine *system;
}
@property(copy) NSString *name;
@property(retain) Machine *system;
@end

// DEALLOC IN @implementation Artist
-(void)dealloc {
    NSLog(@"_deal: %@", self);
    [system release];
    [super dealloc];
}

gary

推荐答案

您必须在每次调用retain或alloc方法时手动调用release。

you must call release by hands for each time you've called retain or alloc method.

这篇关于@property(retain)需要释放吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆