NSMutableArray *array //有54个图片
-(void) clearsome
{
int i;
UIImageView *image;
for(i=0;i<54;i++)
{
image=[array objectAtIndex:i];
[image removeFromSuperview];
[image release];
image =nil; //可有可无吧?
}
[array removeAllObjects]; //为什么运行到这就崩溃了。找了很久都没找到原因
[array release];
}
-(void) clearsome
{
int i;
UIImageView *image;
for(i=0;i<54;i++)
{
image=[array objectAtIndex:i];
[image removeFromSuperview];
[image release];
image =nil; //可有可无吧?
}
[array removeAllObjects]; //为什么运行到这就崩溃了。找了很久都没找到原因
[array release];
}
是不是已经释放了, 再[array removeAllObjects]; 的话 相当于重复释放呢? 重复释放会有这样的问题
-(void) ready
{
array=[[NSMutableArray alloc] init];
int i;
for(i=0;i<54;i+=)
{
UIImageView *image=[[UIImageView alloc] initWithImage://图片];
image.frame=CGRectMake(160+i*2,100,71,96);
[array addObject:image];
[self.view addSubview:image];
[image release];
}
}
只是不显示,没有释放啊
[image release];
那么这个时候指针的计数器为0,调用array removeAllObjects]; 会把array中所有的指针计数器减一,那么就会崩溃了。
总之,你看一下,你在生成这些指针的时候,加入array后是不是调用代码release了?
拿掉就好