Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange releasing problem
    text
    copied!<p>I have got an strange problem but I am quite sure, for you it is not. If it is so, please help me or explain. I have an array of 39 UIImages which will be used for animating UIImageView. and after playing the animation, memory does not release.</p> <pre><code>- (void)viewDidLoad { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; NSMutableArray* actionArray = [[NSMutableArray alloc]initWithCapacity:38]; for (int i=1; i&lt;=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]); } </code></pre> <p>there is no leaks discovered but the amount of memory allocated still is 24 mb.</p> <p>or it is not so necessary ?</p> <p><strong>EDIT:</strong></p> <p>Sorry, my fault. Due to many changes of my code I've got lost in it. After analysing I get it! Thanks a lot!</p> <p>The correct Code is:</p> <pre><code>- (void)viewDidLoad { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; NSMutableArray* actionArray = [[NSMutableArray alloc]initWithCapacity:38]; for (int i=1; i&lt;=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]); } </code></pre> <p>The problem was with <code>[path release];</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload