English 中文(简体)
• 记忆发布
原标题:iPhone Memory release issue
  • 时间:2010-01-11 09:05:17
  •  标签:
  • iphone

I ve some doubts regarding dealloc function in iPhone program. Is it required to give [self.object_name release] or [object_name release] is ok?.. I ve this strange problem in my dealloc function is like this.

-(void) dealloc {
   [self.listOfDates release];
   [self.listOfDescriptions release];
   [super dealloc];
 }

但方案坠毁给EXEC_BAD_ACCESS。 这里,两种物体都是为班级分配全功能的NSMutableArray。 同一职能没有自谋职业的罚款,即:

-(void) dealloc {
    [listOfDates release];
    [listOfDescription release];
    [super dealloc];
 }

在这方面,我如何宣布财产

@property (nonatomic,retain) NSMutableArray *listOfDates;
@property (nonatomic,retain) NSMutableArray *listOfDescription;

在执行档案中,我对这块材料进行了分析,在单项功能中,我已将这些变数如此分配。

self.listOfDates = [[NSMutableArray alloc] init];
self.listOfDescription = [[NSMutableArray alloc] init];

因此,必须自给吗? 我在这里失踪了什么?

当我取消了我用来复制NSMutable Arrays的 mu变功能时,问题得到解决。

-(id)initWithDate:(NSMutableArray *)dates andDescription:(NSMutableArray*)descriptions
{
    if(self = [super initWithNibName:@"DateDescriptionControl" bundle:nil])
    {
        self.listOfDates = [[NSMutableArray alloc] init];
        self.listOfDescription = [[NSMutableArray alloc] init];

        self.listOfDates = [dates mutableCopy];
        self.listOfDescription = [description mutableCopy]; 

    }

   return self;
}

mu除后 制片现在没有扔下EXEC_BAD_ACCESS。 因此,在我犯了错误的地方,我仍然能够说出:

问题回答

无需自行解除交易职能。

你们有两种选择:

[foobar release];

self.foobar = nil;

The second one is equivalent to writing [self setFoobar:nil] and it is inside the setFoobar: method is where the previous value is being released (assuming the property was defined as using retain 或 copy). I tend to prefer the first f或m, where you just send release directly to the object, but either will do.

[自.foobar release],从技术上说应是OK,但如果你后来打电话,则foobar = nil,则该物体将第二次释放(并造成EXC_BAD_ACCESS)。

。 你们想要的是<条码>本身和;有些是

是,

[目标释放];

应处以罚款。

你们面临的基本问题是:

self.listOfDates = [[NSMutableArray alloc] init];

如果财产是“归还的”,如果你通过集束器进入,那么分配给它的物体就应当放在自动释放库中,例如:

self.listOfDates = [[[NSMutableArray alloc] init] autorelease];

但是,这是一种丑恶的行径,国家宇宙航行局提供冰层构造,自动做到:

self.listOfDates = [NSMutableArray array];

您的法典没有使用自动取款机,因此该物体应当放在自动取款库内。 如果你使用非洲资源中心,规则就没有什么不同。

Best Practice(Non ARC). Within your Interface Declare Varibal like below

NSMutableArray *_listOfDates;
NSMutableArray *_listOfDescription;

你们的召集人应当如下。 (与你的法典相同)

@property (nonatomic,retain) NSMutableArray *listOfDates;
@property (nonatomic,retain) NSMutableArray *listOfDescription;

执行

@synthesize listOfDates = _listOfDates, listOfDescription = _listOfDescription;

初始化

-(id)initWithDate:(NSMutableArray *)dates andDescription:(NSMutableArray*)descriptions
{
    if(self = [super initWithNibName:@"DateDescriptionControl" bundle:nil])
    {
        NSMutableArray *tempListOfDates = [[NSMutableArray alloc] init];
        self.listOfDates = tempListOfDates;
        [tempListOfDates release];

        NSMutableArray *tempListOfDescription = [[NSMutableArray alloc] init];
        self.listOfDescription = tempListOfDescription;
        [tempListOfDescription release];
    }
}

页: 1

-(void) dealloc {
    [_listOfDates release];
    [_listOfDescription release];
    [super dealloc];
 }

仅利用[客观释放]释放案件变量。 没有必要使用“自己”。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签