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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:07:34+00:00 2026-06-06T18:07:34+00:00

having a look at the following code: CCSprite* testsprite = [CCSprite spriteWithFile:@test.png]; CCLOG(@1. count:

  • 0

having a look at the following code:

    CCSprite* testsprite = [CCSprite spriteWithFile:@"test.png"];
    CCLOG(@"1. count: %d", [testsprite retainCount]);
    [self addChild:testsprite];
    CCLOG(@"2. count: %d", [testsprite retainCount]);
    [testsprite runAction: [CCMoveTo actionWithDuration:3.0 position:CGPointMake(200.0, 200.0)]];
    CCLOG(@"3. count: %d", [testsprite retainCount]);

the output of this code is:

1. count: 1
2. count: 2
3. count: 3

I think I understand what happens here. The question is the following: is there a rule of thumb when (in which methods) Cocos2D retains objects (in this case testsprite)?

Bye, Christian

  • 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-06T18:07:35+00:00Added an answer on June 6, 2026 at 6:07 pm
    1. If possible use the class functions because they are autoreleased.
    2. Adding a CCNode with addChild will retain the node. If you did some alloc init stuff, release it after adding it as a child
    3. Adding anything to an array retains the object. You can safely release an object if you added it to an array.

    autoreleased:

    CCSprite *sprite = [CCSprite spriteWithFile:@"icon.png"];
    

    manual memory management

    CCSprite *sprite = [[CCSprite alloc] initWithFile:@"icon.png"];
    

    Dont let the retainCount confuse you. Each line of code will maybe retain the object. If it is done well, the underlying code will release it automatically after it is finished.

    A common example when you have to type release.

    NSMutableArray *units = [NSMutableArray array];
    for (int i = 0; i < 42; i++)
    {
        CCNode *unit = [[MyUnit alloc] init]; // retain +1
        [units addObject:unit]; // retain +1
        [unit release]; // retain -1
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a look at the following code http://aperiodic.net/phil/scala/s-99/p26.scala Specifically def flatMapSublists[A,B](ls: List[A])(f: (List[A])
I'm having a look at the code of FastCopy , where I want to
I'm having a look at the code of FastCopy . I want to add
Having a spot of trouble with the following code. The method NextIPID() should simply
I'm having a problem correctly hashing my objects. Consider the following code: class Foo:
We are having 2 problem with jquery. Please have a look at the following...
In my following code, I browse a table and look for columns containing blue
I have a jquery datatable using the following code: // Test list table $('#dashboard_testlist_table').dataTable({
Having a look on the PHP documentation, the following two methods of the DateTime
I am having trouble running the following code. Not sure if I am doing

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.