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 4238618
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:55:41+00:00 2026-05-21T02:55:41+00:00

i’m testing my app on Instruments, and I see that my UIImage and UIImageView

  • 0

i’m testing my app on Instruments,
and I see that my UIImage and UIImageView are memory-leaking like crazy…

I’m basically using recursion, so same variables get to load different images on each call.

    nextImageName = [[NSString alloc] init];
    nextImageName2 = [[NSString alloc] init];
    nextImageName = [[currentPlayers objectAtIndex:playerIndex] retain];
    nextImageName2 = [[currentPlayers objectAtIndex:(playerIndex+1)] retain];
    nextImage = [[UIImage alloc] init];
    nextImage2 = [[UIImage alloc] init];
    nextImage = [UIImage imageNamed:nextImageName];
    nextImage2 = [UIImage imageNamed:nextImageName2];
    nextImageView = [[UIImageView alloc] init];
    nextImageView2 = [[UIImageView alloc] init];
    nextImageView = [[UIImageView alloc] initWithImage:nextImage];
    nextImageView2 = [[UIImageView alloc] initWithImage:nextImage2];
    NSLog(@"r:%d",currentRound);
    NSLog(@"%d vs. %d", playerIndex, playerIndex+1);

    buttonOne = [[UIButton alloc] init];
    buttonTwo = [[UIButton alloc] init];

    playerOne = nextImageView;
    playerTwo = nextImageView2;
    playerOne.frame = CGRectMake(180.0, 200.0, 275.0, 275.0);
    playerTwo.frame = CGRectMake(550.0, 200, 275.0, 275.0);
    buttonOne.frame = CGRectMake(180.0, 200.0, 275.0, 275.0);
    buttonTwo.frame = CGRectMake(550.0, 200.0, 275.0, 275.0);
    [buttonOne addTarget:self action:@selector(announceWinner:)
        forControlEvents:UIControlEventTouchUpInside];
    [buttonTwo addTarget:self action:@selector(announceWinner2:)
        forControlEvents:UIControlEventTouchUpInside];

Could anyone please help me? This is driving me nuts..

I originally had release for all the variables at dealloc, but it seemed it didn’t go into dealloc, so I also put it in viewDidUnload and didReceiveMemoryWarning.

  • 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-21T02:55:41+00:00Added an answer on May 21, 2026 at 2:55 am

    I think the problem is this:

    “I’m basically using recursion, so same variables get to load different images on each call”

    …coupled with this:

    “I originally had release for all the variables at dealloc, but it seemed it didn’t go into dealloc, so I also put it in viewDidUnload and didReceiveMemoryWarning”

    So essentially, if I understand your code correctly, you were making several passes through the alloc/init section over the lifetime of your class, but only ever calling release once, when the class itself is deallocated. I would expect that to leak like crazy.

    You should be able to fix it by changing the alloc/init section to follow a pattern like:

    if (nextImageName) {
        //if it was previously set, release it so that the old instance doesn't leak
        [nextImageName release];
    }
    nextImageName = [[NSString alloc] init];
    
    if (nextImageName2) {
        [nextImageName2 release];
    }
    nextImageName2 = [[NSString alloc] init];
    
    //and so on...
    

    This assumes that these variables are all declared as instance-variables on your class, and that in init you set them all to nil, like so:

    - (void) init {
        if ((self = [super init])) {
            //set default values
            nextImageName = nil;
            nextImageName2 = nil;
            //and so on...
    
            //do other setup things here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.