Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3358094
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:42:39+00:00 2026-05-18T02:42:39+00:00

I have got an strange problem but I am quite sure, for you it

  • 0

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.

- (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]);
}

there is no leaks discovered but the amount of memory allocated still is 24 mb.

or it is not so necessary ?

EDIT:

Sorry, my fault.
Due to many changes of my code I’ve got lost in it. After analysing I get it!
Thanks a lot!

The correct Code is:

- (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]);
}

The problem was with [path release];

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:42:40+00:00Added an answer on May 18, 2026 at 2:42 am

    There are quite a few things wrong with this code. It is a wonder it runs at all.

    First:

    Do not use -retainCount.

    The absolute retain count of an object is meaningless.

    You should call release exactly same number of times that you caused the object to be retained. No less (unless you like leaks) and, certainly, no more (unless you like crashes).

    See the Memory Management Guidelines for full details.


    Now, some of the problems:

    • You asked if you need to empty the array and then said array=nil; … doesn’t work. Setting an array reference to nil doesn’t do anything to the array; doesn’t release it or empty it.

    • you are overreleasing path

    • you are loading a series of images, sticking ’em in an array, and there isn’t anything in that code that is releasing the array (or emptying it). That your app continues to use the memory and shows no leaks sound like correct behavior.

    • Why are you releasing imageView? There is nothing in that code implying that you retained it and, even if it were retained via some other mechanism (IB?), that would be a really odd place to release it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a strange problem about in_array recently which I cannot understand. e.g.
I have got this strange problem.XSL is not working with xml.This is my xml
I have got a strange problem. Can somebody look into it please. I have
I have got a simple but strange problem. I am unable to set size
I got very strange problem. I have one php website which is running in
everyone, I got a strange problem, please help. the error message is: Run-time error
I've got a strange problem which I just can't figure out. I have currencies
I finally got Socket.IO to work properly, but I have encountered a strange problem.
I got a strange problem. I have a tabcontrol and 3 tabs. On every
I've got this strange problem using py-amqp and the Flopsy module. I have written

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.