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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:43:55+00:00 2026-05-23T11:43:55+00:00

[CFString isEqualToString:]: message sent to deallocated instance This is the error I’m getting. I

  • 0

[CFString isEqualToString:]: message sent to deallocated instance

This is the error I’m getting. I have a View controller with a Property that is an NSMutableArray and it contains some Player objects.

Then I have a method that switches to another view, where I can add and remove players. When I load the next view I pass a pointer to the first view, to the second view. I then updated the Array by using [previousView.playerList addObject:p]; where p is the newly created player object.

The error comes, however when I attempt to display the list of players in the second view’s table view. when I try to access [previousView.playerlist objectAtIndex:[indexPath row]]; I get the error above.

here’s the code:

This is in the first View, where it loads the second and passes itself to the property of the second.

- (IBAction) addPlayerButton:(id)sender {
    [self retain];
    PlayerListViewController *playerListViewController = [[PlayerListViewController alloc] init];
    playerListViewController.previousView = self;
    [UIView transitionFromView:self.view toView:playerListViewController.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
}

This is where I initialize the player and add it to the array.

- (IBAction)addPlayer:(id)sender {
    Player *p = [[[Player alloc] initWithPlayerName:playerNameField.text withOrder:[previousView.playerList count] withDelegate:previousView] retain];
    [previousView.playerList addObject:p];
    [playerNameField resignFirstResponder];
    [playerTableView reloadData];
}

And here is where I get my error

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"MyCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
    }
    Player* p = [previousView.playerList objectAtIndex:[indexPath row]];
    [cell.textLabel setText:[p playerName]];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    return cell;
}

I’m getting the error on the line where I set the cell text. [cell.textLabel setText:[p playerName]];

Does anyone know where I’m screwing up? I will post more code if needed.

I trimmed Player.m to only include the Synthesis and Initalization, because the rest is A LOT of code, that doesnt really have to do with this error, because it isin’t being called.

Player.h

@protocol playerProtocol <NSObject>

@optional
- (void) playerDied:(id)playerObject;
- (void) playerWasAdded:(id)playerObject;
- (void) playerLifeDidChange:(id)playerObject;
@end

@interface Player : NSObject {
    id <playerProtocol> delegate;
}
@property (nonatomic,retain) NSString *playerName;
@property (nonatomic, readwrite) int playerLife;
@property (nonatomic, readwrite) int playerPoison;
@property (nonatomic, readwrite) int order;
@property (nonatomic, readwrite) Boolean invincible;
@property (nonatomic, assign) id <playerProtocol>delegate;
@property (nonatomic, retain) UIView *viewPane;
@property (nonatomic) Boolean shown;
@property (nonatomic, readwrite) int minusButton;
@property (nonatomic, readwrite) int plusButton;
@property (nonatomic, retain) UIImageView *readout;
@property (nonatomic, retain) NSArray *playerLifeNumerals;


- (id) initWithPlayerName:(NSString *)playersName withOrder:(int)Order withDelegate:(id)d;
- (void) setPlayerLife:(int)pplayerLife;
- (void) setPlayerPoison:(int)pplayerPoison;
- (NSArray *) getLifeNumeralsFromPlayer:(Player *)playerObject;

@end

Player.m

@implementation Player

@synthesize playerLife, playerName, playerPoison, order, delegate, invincible, viewPane, readout, shown, minusButton, plusButton, playerLifeNumerals;

#pragma mark - Custom Initalizer

- (id) initWithPlayerName:(NSString *)playersName withOrder:(int)Order withDelegate:(id)d {

    [super init];
    delegate = d;
    playerLife = 20;
    playerPoison = 0;
    order = Order;
    playerName = playersName;
    invincible = NO;
    [delegate playerWasAdded:self];
    viewPane = nil;
    readout = nil;
    shown = NO;
    return self;
}

Also here’s the arrays declaration @property (nonatomic, retain) NSMutableArray *playerList;

  • 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-23T11:43:56+00:00Added an answer on May 23, 2026 at 11:43 am

    In:

    - (id) initWithPlayerName:(NSString *)playersName withOrder:(int)Order withDelegate:(id)d {
    
        [super init];
        delegate = d;
        playerLife = 20;
        playerPoison = 0;
        order = Order;
        playerName = playersName;
        invincible = NO;
        [delegate playerWasAdded:self];
        viewPane = nil;
        readout = nil;
        shown = NO;
        return self;
    }
    

    you are not retaining playerName. Note that although you’ve declared your playerName property as retain (and it should be copy instead), you’re not using the property setter in -initWith…. Instead, you’re directly accessing the backing instance variable. Since you’re directly assigning playersName to the instance variable, you need to manually send it -retain (or, better yet, -copy).

    Check whether you need this in your other declared properties. Also, you should follow the idiom:

    self = [super init];
    if (self) { … }
    return self;
    

    in your initialisers.

    Edit: you need to carefully review your code with regard to memory management practices since you’re leaking in more than one place. For example, in:

    - (IBAction) addPlayerButton:(id)sender {
        [self retain];
        PlayerListViewController *playerListViewController = [[PlayerListViewController alloc] init];
        playerListViewController.previousView = self;
        [UIView transitionFromView:self.view toView:playerListViewController.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
    }
    

    what’s the purpose of [self retain], and is there a balancing release?

    Another example: in:

    Player *p = [[[Player alloc] initWithPlayerName:playerNameField.text withOrder:[previousView.playerList count] withDelegate:previousView] retain];
    [previousView.playerList addObject:p];
    

    you get +1 ownership from +alloc, another +1 from -retain, and the array also owns p, hence another +1. You should replace -retain with -autorelease to balance the number of times you’re taking ownership of that object.

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

Sidebar

Related Questions

-[CFString respondsToSelector:]: message sent to deallocated instance 0x4b9e720 I don't where to start, tried
am getting the following error while scrolling the UITableview . EXC_BAD_ACCESS , -[CFString retain]:
I have follow code to make a String to a CFString: internal static byte[]
I am using C# and the .NET 2.0 framework. I have this method here
If I have a class/object like this #import <Foundation/Foundation.h> @interface anObject : NSObject {
I am getting error code like follows (gdb) continue Current language: auto; currently objective-c
I've got a weird linker issue. I have code that looks like so: double
I am getting a casting error. My app is reading a text file from
I have the same project, that at the beginning, it worked also on ipad,
I am testing an EXE_BAD_ACCESS error. I have set NSZombieEnabled, MallocStackLogging, MallocStackLoggingNoCompact to YES.

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.