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

  • SEARCH
  • Home
  • 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 7750363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:16:19+00:00 2026-06-01T11:16:19+00:00

I have an NSMutableArray called message that I’ve alloc’d in init and release in

  • 0

I have an NSMutableArray called message that I’ve alloc’d in init and release in dealloc. I can usually use a string in a CCCallFuncND action without a problem, even if it’s an index of an array, such as:

displayMessagePiece = [CCCallFuncND actionWithTarget:self selector:@selector(displayMessageBoxString : data:) data:[[NSString stringWithFormat:[labelPieces objectAtIndex:i]] retain]];

However, if I use my mutable string, I get a crash with a green arrow pointing to my line of code that I have it in, and it says “EXC_BAD_ACCESS” with some hexadecimal.

Here’s my action and sequence where I’m trying to use NSMutableString:

id displayMessage = [CCCallFuncND actionWithTarget:self selector:@selector(displayMessageBoxString : data:) data:[[NSString stringWithFormat:[message copy]] retain]];

[self runAction:[CCSequence actions:displayMessage,nil]];

Notice I use [message copy], although I’ve tried also just message.

  • 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-06-01T11:16:21+00:00Added an answer on June 1, 2026 at 11:16 am

    I smell bad practice:

    NSString* s = [[NSString stringWithFormat:[labelPieces objectAtIndex:i]] retain];
    [CCCallFuncND actionWithTarget:self 
                          selector:@selector(displayMessageBoxString:data:)
                              data:s];
    

    First of all you are retaining a string that you may or may not be releasing. There is no guarantee that the displayMessageBoxString selector ever gets called. For example, the node running the call func action may be removed from the scene before the selector is called, or you may be changing the entire scene before the selector is called. In both cases you will be leaking the string.

    There’s also no reason to use CCCallFuncND when there’s CCCallFuncO. CCCallFuncND is particularly harmful when your project is using ARC. In that case you’d have to bridge cast the object to void*, at which point ARC might simply release the memory, rightfully assuming that non-ARC code now manages the object’s memory. The same may actually be true for autorelease, but I’m not 100% certain about that.

    So first order of business is to use CCCallFuncO and re-test if your problem is gone. Also rely on autorelease, do not retain the string since you will not be able to release it in all cases.

    NSString* s = [NSString stringWithFormat:[labelPieces objectAtIndex:i]];
    [CCCallFuncO actionWithTarget:self 
                         selector:@selector(displayMessageBoxString:)
                           object:s];
    

    Now if your minimum target is iOS 4.0, you should really be using blocks instead. This is particularly true if you need both sender and object at the same time. The block has access to the local scope, so you can use the simplest CCCallBlock action in this case:

    NSString* s = [NSString stringWithFormat:[labelPieces objectAtIndex:i]];
    [CCCallBlock actionWithBlock:^void(){
        CCLOG(@"sender is: %@, string is: %@", self, s);
    }];
    

    Et voila, all problems solved and guaranteed not to cause any memory leaks.

    Note that you can also write the block without void() like this:

    [CCCallBlock actionWithBlock:^{
        CCLOG(@"sender is: %@, string is: %@", self, s);
    }];
    

    Personally I find it helpful to remind myself and others about the return type and parameters, even if there are none.

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

Sidebar

Related Questions

I have a NSMutableArray that I need to search for a string and return
I have a class that subclasses NSMutableArray. I init it using: MyClass class =
I have a NSMutableArray property declared as (nonatomic, retain) called Categories. In dealloc, I
I have a NSMutableArray (called listOfSites) that is created and used in classA.m. I
I have an NSMutableArray that is populated with objects of strings. For simplicity sake
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
I have this code: tableList = [[NSMutableArray alloc] initWithObjects:@First View,@Second View,nil]; I have synthesized
I have a class called Shop that contains data members ( NSString , NSInteger
I have a custom class of type NSObject that contains a single NSMutableArray. This
I'm using Cocoa Touch to build an iPhone app. I have an NSMutableArray called

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.