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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:41:51+00:00 2026-05-15T10:41:51+00:00

I am writing the code using cocos2d. I want to release all the memory

  • 0

I am writing the code using cocos2d.
I want to release all the memory I allocated. I have done it in dealloc method in the following way.
All the objects I released are declared in interface file and property (assign) was set and are synthesized in implementation file.
I used alloc method to create them like

self.PlayerA = [[CCSprite alloc] initWithFile:@" PlayerImage_01.png"];


-(void)dealloc
{
 int count , i ;

 count = [self.PlayerA retainCount];
 for(i = 0; i < count; i++)
   [self.PlayerA release];

 count = [self.targetLayer retainCount];
 for(i = 0; i < count; i++)
   [self.targetLayer release];

  count = [self.playerGunSlowDrawSheet retainCount];
 for(i = 0; i < count; i++)
    [self.playerGunSlowDrawSheet release];

 count = [self.playerGunSlowDrawAnimation retainCount];
 for(i = 0; i < count; i++)
    [self.playerGunSlowDrawAnimation release];

 count = [self.numberFinishedTime retainCount];
 for(i = 0; i < count; i++)
    [self.numberFinishedTime release];

 count = [self.backGroundImage retainCount];
 for(i = 0; i < count; i++)
   [self.backGroundImage release];

 [[CCTextureCache sharedTextureCache] removeAllTextures];
 [[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];

 [super dealloc];
 }

But I am getting: Program received signal: “EXC_BAD_ACCESS”.
I debugger it is showing the error at [super dealloc];

Am I totally wrong in the memory management ? Or am I missing anything in this.
Thank you.

  • 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-15T10:41:51+00:00Added an answer on May 15, 2026 at 10:41 am

    Yes, this isn’t a good way to release objects. By releasing object A multiple times in your dealloc method (if it’s retain count > 1), you are potentially pulling the rug out from under any other object that might be using an object.

    You should only be releasing the object once (assuming you only retain the object once or you alloc it yourself) if you own it.

    For more information on “owning” objects, I recommend you read Apple’s Memory Management Programming Guide at:

    http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

    Using the Build and Analyze item in your XCode’s Build menu should help find issues like this, once you understand the basics of Objective-C Memory Management

    Typically, a dealloc method should look like this:

    -(void) dealloc
    {
        [self.objectA release];
        [self.objectB release];
    
        [super dealloc];
    }
    

    edit: To answer your original question as to why you are getting EXC_BAD_ACCESS, there is not enough information here to determine why. One possible reason may be that you are deallocing an object in your sub class that also gets dealloc’ed in your super class’s dealloc method. But that is just a shot in the dark

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

Sidebar

Related Questions

I am looking at better way of writing following code using linq/lambda expression.. I
Greetings all. I am writing some code using the Boost Units library and have
When writing C++ code I've learned that using the stack to store memory is
I am writing a game for the iPhone/iPodTouch (using Cocos2d) and I have noticed
I'm writing code using Oracle SQL Developer. I have a simple select statement that
I'm writing code using the C intrinsics for Intel's AVX instructions. If I have
I am writing code in VS2005 using its STL. I have one UI thread
I write code with Python using Django framework. Now I have read about all
I am writing code for a windows application using vb.net. I want to open
I have writing Java code Using Jersey library to call Rest APIs. For my

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.