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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:43:52+00:00 2026-06-11T10:43:52+00:00

I got a GameScene class that is not a singleton instance. Hence I allocate

  • 0

I got a GameScene class that is not a singleton instance. Hence I allocate and deallocate it every time the user chooses a new level and keep the “static”/”shared” data in a different singleton class (E.g. GameManager).

I am using ARC. I would like to understand if my approach is correct under the memory management point of view. In other words, is it enough to call “removeUnusedSpriteFrames” at cleanup? Will this remove all sprites in game-art-forLevelOne-hd.plist? Should I do something also with the CCSpriteBatchNode?

-(void) loadGameArtFileForLevelOne  //I do this in a switch but this is to simplify the reading 
{
    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
    [frameCache addSpriteFramesWithFile:@"game-art-forLevelOne-hd.plist"];
    CCSpriteBatchNode * sharedSpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"game-art-forLevelOne-hd.png"];    
 }

//As dealloc is deprecated for ARC code, I prefer to remove unused sprites and texture on cleanup
-(void) cleanup
{
    [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];     
}

I added a CCLOG call in the dealloc method of CCSpriteBatch node. When I load the GameScene and then go back to the menu I see the log of “remove unused texture” as expected but I don’t see any log of the dealloc method of CCSpriteFrameCache. *!! Warning: See edit below – my mistake!!*

EDIT: Sorry, I meant I don’t see any log of the dealloc method of CCSpriteBatch

This concerns me slightly as I want to “free” and remove all memory related to the Sprites for the level.

Once I understood this I will then “optimize” this bit (e.g. have one sprite sheet for each class of level – e.g. world 1 – and one sprite sheet for each background).

Any suggestion?

  • 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-11T10:43:53+00:00Added an answer on June 11, 2026 at 10:43 am

    EDIT:

    I assume you are adding the CCSpriteBatchNode node somewhere, although the code you posted does not show it (you also mention, it happens in a switch, so I think in a completely different settings). If so, it will not be deallocated until you remove it from where you added it to.

    Here, maybe, a clarification is in order.

    The CCSpriteFrameCache is a cache: a piece of storage where all the sprites get in order to be readily available for reuse.

    The CCSpriteBatchNode is a mechanism for improving performance in the Open GL layer in principle totally unrelated from the cache.

    I understand that if you have some sprite used through a batch node still present in some layer/node/scene, than it will not be considered “unused” and will not be removed by your cleanup code. Actually, it is in use. The cached sprite will become “unused” when you remove it from all the nodes that refers to it.

    As to your question:

    In other words, is it enough to call “removeUnusedSpriteFrames” at cleanup?

    Well, I think that it depends on your app what could be considered good cleanup. Removing unused sprites from the cache is certainly ok; but you might also do other things: unloading audio resources you loaded; removing parts of the scene that are not used (and could be reloaded if required); etc.

    Hope this helps.

    I don’t see any log of the dealloc method of CCSpriteFrameCache.

    CCSpriteFrameCache is a singleton, so it shall exist for the lifetime of the program (it could be different, but I bet this is the case):

     CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
    

    So, I would not be worried at the fact that the Cache is not deleted; what matters is that its content is emptied.

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

Sidebar

Related Questions

Got a class that serializes into xml with XMLEncoder nicely with all the variables
Got the new Retina MacBook and it has not been playing nice with xCode.
Got Ejb @Stateless @Local public class UserManagerBean implements UserManagerBeanLocal { @TransactionAttribute(TransactionAttributeType.REQUIRED) public Long registerUser(User
Got this ScopeExit class off code-project but it would not build on GCC 4.5.3.
Got a seg fault from my memcpy that gdb can't give me anything else
got some problems. Built an applet that has to be used step-by-step. After each
Got a task to make a program that registers animals and the object is
Got this error trying to do a new project with rails 3.2. haml issue
Got that error when trying to push updated app to Heroku (probably the same
Got this: http://jsfiddle.net/NdsF8/ Want it to be dynamic so when you click a new

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.