使用多维数组的内存泄漏

时间:2011-06-21 05:45:50

标签: iphone

enter image description here 我在那个多维可变数组中得到了memoery泄漏我需要删除那些泄漏,因为由于这个泄漏app在iphone中不起作用,我知道如何删除这个泄漏

  

CGRect bounds = [self bounds];

UITouch*            touch = [[event touchesForView:self] anyObject];
if (firstTouch) {
    firstTouch = NO;
    previousLocation = [touch previousLocationInView:self];
    previousLocation.y = bounds.size.height - previousLocation.y;
    NSMutableArray *temp=[[NSMutableArray alloc]init];
    [undo addObject:temp];
    /***** add 1st point *********/
    [[undo objectAtIndex:[undo count] -1] addObject:[NSValue valueWithCGPoint:previousLocation]];

    if(mcount==1)
    {
        [masking addObject:[[NSMutableArray alloc]init]];
        [[masking objectAtIndex:[masking count]-1] addObject:[NSValue valueWithCGPoint:previousLocation]];
    }
} else {

    location = [touch locationInView:self];
    location.y = bounds.size.height - location.y;
    previousLocation = [touch previousLocationInView:self];
    previousLocation.y = bounds.size.height - previousLocation.y;


    [[undo objectAtIndex:[undo count] -1]addObject:[NSValue valueWithCGPoint:previousLocation]];

    if(mcount==1)
    {
         [[masking objectAtIndex:[masking count]-1] addObject:[NSValue valueWithCGPoint:previousLocation]];
    } 
}

1 个答案:

答案 0 :(得分:2)

这一行:

NSMutableArray *temp=[[NSMutableArray alloc]init];

似乎在泄漏。完成后发布temp或此行中autorelease

这一行:

[masking addObject:[[NSMutableArray alloc]init]];

也有问题。由于没有直接指针,我推荐autorelease(或重写此代码,但我离题了。)

也可能对您有所帮助,您可以更改

[undo objectAtIndex:[undo count] -1]

改为

[undo lastObjectAtIndex]