NSMutableArray * array / / There are 54 pictures
- (Void) clearsome
{
int i;
UIImageView * image;
for (i = 0; i <54; i + +)
{
image = [array objectAtIndex: i];
[Image removeFromSuperview];
[Image release];
image = nil; / / optional, right?
}
[Array removeAllObjects]; / / Why run into this crash. Looking for a long time failed to find the cause
[Array release];
}
Reply:
[Image removeFromSuperview];
Is not been released, then [array removeAllObjects];?, Then release it corresponds repeat repeat release have this problem
Reply:
My array
- (Void) ready
{
array = [[NSMutableArray alloc] init];
int i;
for (i = 0; i <54; i + =)
{
UIImageView * image = [[UIImageView alloc] initWithImage :/ / Pictures];
image.frame = CGRectMake (160 + i * 2,100,71,96);
[Array addObject: image];
[Self.view addSubview: image];
[Image release];
}
}
Reply:
[Image removeFromSuperview];
Just do not show that there is no release ah
Reply:
stored in the array is a pointer, a pointer is alloc these imageview out when alloc when the counter is a pointer, added to the array when the counter is incremented by one into two, you are not adding after release once, this time, the counter becomes one, you are here and use the image = [array objectAtIndex: i];
[Image release];
So this time the pointer counter to 0, calling array removeAllObjects]; put all the pointers array counter by one, it will collapse.
Anyway, you look, you generate these pointers when, after joining the array is not the calling code release?
Reply:
[Image release];
Remove fine
Reply:
Four fifth positive solutions
No comments:
Post a Comment