У меня странная проблема, но я совершенно уверен, что для вас это не так. Если это так, пожалуйста, помогите мне или объясните.
У меня есть массив из 39 UIImages, которые будут использоваться для анимации UIImageView. и после воспроизведения анимации память не освобождается.
- (void)viewDidLoad {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSMutableArray* actionArray = [[NSMutableArray alloc]initWithCapacity:38];
for (int i=1; i<=39; i++) {
NSString* path = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"bg_Level1_%.4d", i] ofType:@"png"];
UIImage *image = [[UIImage alloc]initWithContentsOfFile:path];
[path release];
[actionArray addObject:image];
[image release];
NSLog(@"path rc %d image %d", [path retainCount], [image retainCount]);
}
imageView.animationImages = actionArray;
imageView.animationDuration = 4.0;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
NSLog(@"RetainCount ActArr %d ImageView %d", [actionArray retainCount], [imageView retainCount]);
[actionArray release];
[pool drain];
[imageView release];
[self performSelector:@selector(playAnimation2) withObject:self afterDelay:5.0];
[super viewDidLoad];
}
-(void)playAnimation2{
if ([imageView isAnimating]) {
[imageView stopAnimating];
}
NSLog(@"RetainCount ImageView %d",[imageView retainCount]);
}
утечек не обнаружено, но объем выделенной памяти по-прежнему составляет 24 МБ.
или это не так нужно?
EDIT:
Извините, моя вина.
Из-за многих изменений в моем коде я потерялся в нем. После анализа я понял!
Большое спасибо!
Правильный код:
- (void)viewDidLoad {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSMutableArray* actionArray = [[NSMutableArray alloc]initWithCapacity:38];
for (int i=1; i<=39; i++) {
NSString* path = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"bg_Level1_%.4d", i] ofType:@"png"];
UIImage *image = [[UIImage alloc]initWithContentsOfFile:path];
// [path release];
[actionArray addObject:image];
[image release];
NSLog(@"path rc %d image %d", [path retainCount], [image retainCount]);
}
imageView.animationImages = actionArray;
imageView.animationDuration = 4.0;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
NSLog(@"RetainCount ActArr %d ImageView %d", [actionArray retainCount], [imageView retainCount]);
[actionArray release];
[pool drain];
[self performSelector:@selector(playAnimation2) withObject:self afterDelay:5.0];
[super viewDidLoad];
}
-(void)playAnimation2{
if ([imageView isAnimating]) {
[imageView stopAnimating];
}
[imageView removeFromSuperview];
imageView.animationImages = nil;
NSLog(@"RetainCount ImageView %d",[imageView retainCount]);
}
Проблема была с [path release];