关于内存泄漏问题

时间:2011-02-08 06:38:04

标签: iphone

我是iPhone开发的新手。我在以下代码中遇到内存泄漏问题。如果有人知道为什么会这样,请帮助我。

for(int i=0;i<size;i++)
{
    NSString *CellIdentifier1;
    if(universalApp==2)
    {
    CellIdentifier1 = @"CustomThumbImageTableCell_iphone";
    cell = [[[CustomThumbImageTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];

        //NSLog(@">>>>> Creating image >>>>>>>>");
    cell.thumbImageView = [[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)];


    [imgViewArray addObject:cell.thumbImageView];
    [cell.thumbImageView release];  

}

1 个答案:

答案 0 :(得分:1)

此外,使用自动释放池,

for(int i=0;i<size;i++) {


NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

...
cell.thumbImageView = [[[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)] autorelease];
...

[pool release];
}

如你所知,检查imgViewArray,添加到NSMutableArray的对象的保留计数增加1。