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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:50:20+00:00 2026-05-27T23:50:20+00:00

I can’t work out what I am doing wrong with an NSMustableArray. It is

  • 0

I can’t work out what I am doing wrong with an NSMustableArray. It is fair to say that I don’t really understand memory allocation that well, so I apologize if this is a simple questions.

I have a tab bar application that is working well, and on one of the tab bars I have a front view and a back view of a person.

In the .h I have

@interface BurnsCalculatorViewController : UIViewController// <UIPickerViewDelegate, UIPickerViewDataSource>
{
    UIView              *frontView;
    UIView              *backView;
    UIButton            *frontButton;
    UIButton            *backButton;
    NSMutableArray      *frontBurnsArray;
}

@property (nonatomic, retain) UIView            *frontView;
@property (nonatomic, retain) UIView            *backView;
@property (nonatomic, retain) UIButton          *frontButton;
@property (nonatomic, retain) UIButton          *backButton;
@property (nonatomic, retain) NSMutableArray    *frontBurnsArray;

-(IBAction)frontButtonSelect:(id)sender;
-(IBAction)backButtonSelect:(id)sender;

@end

Then I have the .m file

@implementation BurnsCalculatorViewController

@synthesize frontView;
@synthesize backView;
@synthesize frontButton;
@synthesize backButton;
@synthesize frontBurnsArray;

-(IBAction)frontButtonSelect:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES];
    [self.view addSubview:backView];
    [self.view addSubview:backButton];
[UIView commitAnimations];
    NSLog(@"%@", frontBurnsArray);
}

-(IBAction)backButtonSelect:(id)sender
{
    [UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES];
    [self.view addSubview:frontView];
    [self.view addSubview:frontButton];
[UIView commitAnimations];
    NSLog(@"%@", frontBurnsArray);
}

-(void)viewDidLoad
{
    frontBurnsArray = [NSMutableArray arrayWithObjects: @"frontHead", @"frontChest", @"frontAbdomen", @"frontGroin",@"frontLeftArm", @"frontLeftForeArm", @"frontRightArm", @"frontRightForearm", @"frontLeftThigh", @"frontLeftLowerLeg", @"frontRightThigh", @"frontRightLowerLeg",nil];

    CGRect viewframe = CGRectMake(0, 0, 320, 480);
    frontView = [[UIView alloc] initWithFrame:viewframe];
    frontView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:frontView];

    frontButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [frontButton addTarget:self action:@selector(frontButtonSelect:) forControlEvents:UIControlEventTouchDown];
    [frontButton setTitle:@"Show Back" forState:UIControlStateNormal];
    frontButton.frame = CGRectMake(210, 10, 100, 30);
    [self.view addSubview:frontButton];

    backView = [[UIView alloc] initWithFrame:viewframe];
    backView.backgroundColor = [UIColor blackColor];
    backButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
    [backButton addTarget:self action:@selector(backButtonSelect:)forControlEvents:UIControlEventTouchDown];
    [backButton setTitle:@"Show Front" forState:UIControlStateNormal];
    backButton.frame = CGRectMake(210, 10, 100, 30);
}

-(void)dealloc
{
    [super dealloc];
    [frontButton release];
    [backButton release];
    [frontBurnsArray release];
}
@end

What I can’t figure out is why the NSLogs in the IBActions are both telling me that the instance has been deallocated. Apart from the “release” in the dealloc, I am have said to retain the array and have not released it elsewhere.

I have spent ages searching for an answer to this, but just can’t figure it out.

Thanks!!

  • 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-27T23:50:21+00:00Added an answer on May 27, 2026 at 11:50 pm
    frontBurnsArray = [NSMutableArray arrayWithObjects: @"frontHead", @"frontChest", @"frontAbdomen", @"frontGroin",@"frontLeftArm", @"frontLeftForeArm", @"frontRightArm", @"frontRightForearm", @"frontLeftThigh", @"frontLeftLowerLeg", @"frontRightThigh", @"frontRightLowerLeg",nil];
    

    You are not using the retaining property

    try

    self.frontBurnsArray = [NSMutableArray arrayWithObjects: @"frontHead", 
                                                             @"frontChest",
                                                             @"frontAbdomen", 
                                                             //....
                                                             nil];
    

    You are creating an array, that is autorealesed, meaning it will disappear on the next run-loop. If you assign it to the property, it get automatically retained and will exists until you release it. you also could call

    frontBurnsArray = [[NSMutableArray arrayWithObjects: @"frontHead", 
                                                             @"frontChest",
                                                             @"frontAbdomen", 
                                                             //....
                                                             nil] retain];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't work out a way to make an array of buttons in android. This
Can anyone help me trying to find out why this doesn't work. The brushes
Can somebody point me to a resource that explains how to go about having
Can a LINQ enabled app run on a machine that only has the .NET
Can anyone help me as what is going wrong here? Am not able to
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can some one Guide me to work with these things... What is Model popup
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can anyone help me with an excel formula that groups related rows and creates
can you show me how to assign css properties to the button that is

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.