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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:15:16+00:00 2026-05-15T02:15:16+00:00

I tried storing some CCSprites in a NSMutableArray, but the game crashed immediately, I’m

  • 0

I tried storing some CCSprites in a NSMutableArray, but the game crashed immediately, I’m guessing it’s a memory problem, and I’m also guessing that CCSprites are autorelease objects?

So, how would I store multiple CCSprites in a NSMutableArray?

The purpose I wanna do this is store for example all enemies in an array, and then loop through them in my timestep function and update their positions and whatnot.

What I tried to do:

NSMutableArray *enemies = [NSMutableArray array];
[enemies addObject: [CCSprite spriteWithFile: @"hello.png"]];

It crashes when I try to reach the sprite using -objectAtIndex:

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

    The array is autoreleased. If you try to access it later in another context, it probably already died. So you either retain it or don’t use the convenience array method, but [[NSMutableArray alloc] init] explicitly.

    Or store it in a retained property (be sure to use the setter method in that case, i.e. self.ivar = enemies;

    Whichever way you go, be cautious not to “over-retain” your array, i.e. using alloc/init and the retaining setter, or your array will never get freed again (more correctly it will only get freed with a “buggy” double release).

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

Sidebar

Related Questions

i'd like to set up some global variables for storing several things. i've tried
So I'm actually storing an html field, but I'd like to add some pseudo
I've tried some codes like string s = this is example; txt1TextBlock.Text = Thread.CurrentCulture.TextInfo.ToTitleCase(s);
I know that for an integer, you can use: int value; I tried: string
I tried decoding this base64 string so many times but every time i get
Let us say we have some code that looks like below: @interface SomeClass :
I'm storing some blobs in my database, so I have a Document table and
I've a xml file in which I'm storing some HTML content in an element
I have some simple JavaScript that determines where a click happens within a browser
I have deployed a web service with Jax-ws that use a database for storing

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.