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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:04:49+00:00 2026-05-30T06:04:49+00:00

I recently posted a question here about some memory issues I was having. I’ve

  • 0

I recently posted a question here about some memory issues I was having. I’ve got that fixed now thanks to this wonderful community but I’m facing another problem. I’m using Cocos2d to develop a game and I’m trying to remove a Sprite from and array. The problem arises when I try and release the temporary array I’m using to keep track of the sprites to remove.

    NSMutableArray *spritesToRemove = [[NSMutableArray alloc] init];

    // Loop through all sprites
    for(CSSprite *sprite in _sprites){
        if(sprite.toRemove){
            [spritesToRemove addObject: sprite];
        }
    }

    // loop through sprites to be removed
    for(CSSprite *removeableSprite in spritesToRemove){

        [_sprites removeObject: removeableSprite];

        // Cocos2d code to remove a sprite
        [self removeChild: removeableSprite cleanup: YES]; 
    }

    [spritesToRemove release]; // EXC_BAD_ACCESS error 

I get a feeling the reason I’m getting the error is because I’m releasing the sprite object in [self removeChild: removeableSprite cleanup: YES]; before actually releasing the array. It all works fine if I remove the line [spritesToRemove release] but I obviously then have a memory leak on my hands.

I’ve tried moving the removal of the sprites around and I can get the memory thing sorted by completely omitting the line [self removeChild: removeableSprite cleanup: YES]; but then Cocos2d throws the same EXC_BAD_ACCESS error from within CCNode at [child visit]; of -(void) visit

Thanks again for your help 🙂

EDIT: I enabled NSZombie and I got this message:

*** -[Sprite release]: message sent to deallocated instance 0xfa94cf0

Which to me kind of suggests my initial thought, somewhere an entry in the array is being released to soon. Would that be correct? If so is there anyway for me to find out where?

  • 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-30T06:04:50+00:00Added an answer on May 30, 2026 at 6:04 am

    I managed to find the issue (and to be honest I feel a little silly 😛 ). I was releasing the sprite manually once I added it to the array, which wasn’t in the code provided so you guys couldn’t have found it. The sprite was already set up to be autoreleased and thus was being cleared twice – causing my error.

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

Sidebar

Related Questions

As some may be aware, I recently posted about high memory usage on my
Recently I posted a question about the html helper dropdownlist and got it working
I recently posted this question about codes for a gift-card-like voucher that users can
I recently posted a question about Azure... is it really an OS? I understand
I recently posted a question about centering a page with CSS. I figured out
I recently posted a question about optimizing the algorithm to compute the Levenshtein Distance,
I recently posted a question about getting last 3 results in table in the
I recently posted this question on the r-help mailing list but got no answers,
I've been working on some solutions for some questions that have been recently posted
Recently i posted a question about what the variable is of a file which

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.