<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Tag: memory management - Recent Topics</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/memory-management</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 04:34:24 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/tags/memory-management/topics" rel="self" type="application/rss+xml" />

		<item>
			<title>moomy on "hud layer release question"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28848#post-142141</link>
			<pubDate>Wed, 01 Feb 2012 13:32:35 +0000</pubDate>
			<dc:creator>moomy</dc:creator>
			<guid isPermaLink="false">142141@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi there,  I have made a hud layer.<br />
In my action layer I make reference to the hud layer...</p>
<p>HudLayer *hud;<br />
}<br />
@property (nonatomic, retain) HudLayer *hud;</p>
<p>Everything seems to work perfectly.</p>
<p>The problem is that when I look in dealloc of my actonLayer.mm it says "on "dealloc" you need to release all your retained objects"  I then notice that I have retained hud.</p>
<p>I have tried adding self.hud = nil;  and [hud release];  into the actionLayer dealloc....  but the app crashes with both of these.</p>
<p>I have added a checker of CCLOG(@"dealloc:%@", self); in my dealloc which does get called when I exit actionLayer.</p>
<p>Just wondered... do I need to release hud, or is there a way to not retain it??</p>
<p>sorry if the solution is obvious, I'm not too experienced with this.<br />
thanks<br />
moomy
</p></description>
		</item>
		<item>
			<title>vishalavalani on "Cocos2d and ARC"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25678#post-133693</link>
			<pubDate>Fri, 16 Dec 2011 09:35:45 +0000</pubDate>
			<dc:creator>vishalavalani</dc:creator>
			<guid isPermaLink="false">133693@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am using Xcode 4.2 and building a game for iphone (from iOS 3.0 - 5.0). Does cocos2d support ARC? What modifications needs to be made to convert code written in previous versions?</p>
<p>If I use the strong and weak keywords for variables and set compiler to LLVM GCC 4.2, what will be the results? Is it a necessity to change compiler to 3.0 to support ARC?</p>
<p>Can anyone point me in the right direction?</p>
<p>Thanks!
</p></description>
		</item>
		<item>
			<title>BarnabyByrne on "cocos2d memory management questions"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25627#post-133434</link>
			<pubDate>Thu, 15 Dec 2011 04:21:35 +0000</pubDate>
			<dc:creator>BarnabyByrne</dc:creator>
			<guid isPermaLink="false">133434@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi</p>
<p>First of all let me say that I think cocos2d is a great framework.  I am close to completing my first project but want to be sure about autoreleasing memory.</p>
<p>When you start a new project in Xcode using the cocos2d template, I've noticed the main.m function contains this code:</p>
<p>int main(int argc, char *argv[]) {</p>
<p>    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];<br />
    int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");<br />
    [pool release];<br />
    return retVal;<br />
}</p>
<p>Does that mean you never have to alloc or release any variables throughout your game?<br />
Also what is the memory scope of variables being declared within functions?  Does the autorelease free them up after the function has returned?</p>
<p>I've noticed a lot (and I mean a lot) of allocation in the memory trace section in instruments while my game is running on my device, and that often in activity monitor that real memory increases slowly 0.1mb at a time - although I have not noticed it fluctuating more than about 10mb in total so far (starts at 31 goes up to about 41mb).</p>
<p>I'm also slightly unsure about what should be in my -(void) dealloc function.  Can someone advise me on set practice and suggest any pitfalls to avoid in case I'm not releasing anything that may be contributing to these observations?
</p></description>
		</item>
		<item>
			<title>Viacheslav on "CCSpriteBatchNode problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25416#post-132293</link>
			<pubDate>Thu, 08 Dec 2011 16:57:02 +0000</pubDate>
			<dc:creator>Viacheslav</dc:creator>
			<guid isPermaLink="false">132293@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello to everyone,</p>
<p>In my game i use CCSpriteBatchNode , next i will post game logic :</p>
<p>1. In global defines.h i create variable with name : </p>
<p>CCSpriteBatchNode	*spritesBgNode;</p>
<p>// Below code playScene.m (my game scene).<br />
2. In init create batch node </p>
<p>spritesBgNode = [[CCSpriteBatchNode alloc] initWithFile:@"spriteSheet.png" capacity:70];<br />
[self addChild:spritesBgNode z:2];</p>
<p>3. Use batch node and add some sprites in it :</p>
<p>// Bomb inherit from CCSprite<br />
Bomb *newBomb;<br />
newBomb = [[Bomb alloc]initWithImage:@"blueBomb1.png" Type:kCollisionType_BlueNinja Position:storagePoint AndVelocity:cpvzero];<br />
if (newBomb) {<br />
            [spritesBgNode addChild:newBomb];</p>
<p>            [newBomb release];<br />
        }</p>
<p>4. After some time i want to switch scene from playScene to playScene to start next level and in dealloc i call</p>
<p>[spritesBgNode removeFromParentAndCleanup:YES];<br />
[spritesBgNode release];<br />
spritesBgNode = nil; </p>
<p>5. I use chipmunk2d bode and shape for each newBomb<br />
6. When start next scene (see step 4) bombs sprite became invisible !!! I know it because with i can see in physic debug mode shapes. </p>
<p>I test same code without batch node just [self addChild:newBomb z:2]; and all ok , but when i use batch node sprites became invisible after [[CCDirector sharedDirector] replaceScene: [PlayScene scene]];</p>
<p>Any ideas ?</p>
<p>Thank you.
</p></description>
		</item>
		<item>
			<title>Jamorn on "Object Initializing with not 1, not 2, but 3 retain counts! WHY?!"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21606#post-120047</link>
			<pubDate>Fri, 07 Oct 2011 12:26:55 +0000</pubDate>
			<dc:creator>Jamorn</dc:creator>
			<guid isPermaLink="false">120047@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi guys, I didn't think I'd have to resort to posting another question topic on memory leaks as there are plenty out there to answer most questions, but this one I'm just stumped.</p>
<p>Now, I am in the process of chasing down leaks in my code and found something quite unusual.</p>
<p>Normally I believe the retain count of an object only changes with:</p>
<p>INCREASE: alloc+init, copy, retain, mutablecopy.</p>
<p>DECREASE: release, autorelease (when the Autorelease pool is drained)</p>
<p>However, I realize that some of my objects are not being deallocated when I replace my scene as they still have retain counts of &#62; 0 so I get leaks. So when I checked, apparently right after this init line:</p>
<pre><code>Widget *widget1 = [[[Widget alloc] initWithInt:10 speed:4.0f] autorelease];
NSLog(@&#34;[After Init] Widget Retain Count = %d&#34;, widget1.retainCount);</code></pre>
<p>The retain count is 3! (Note the autorelease has no effect on retain count here until the pool is drained.) So I'm getting 2 extra retain counts from nowhere. How is this possible?
</p></description>
		</item>
		<item>
			<title>jetstream on "scenes dealloc correctly yet Overall Bytes goes up"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20386#post-113354</link>
			<pubDate>Tue, 30 Aug 2011 01:09:24 +0000</pubDate>
			<dc:creator>jetstream</dc:creator>
			<guid isPermaLink="false">113354@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>this community is great. a few of you have reviewed my code and determined that the scenes are deallocing correctly. </p>
<p>so, the scene management is fine, but 15-20 megs are being used by the device for each scene....and i'm never able to free that memory once i've moved on from a scene. </p>
<p>basically i watch the "Overall bytes" go up in Instruments allocations and the app crashes around 128 megs or so. also this doesn't help between scenes:<br />
[[CCTextureCache sharedTextureCache] removeUnusedTextures];</p>
<p>i also remove the touch dispatcher each time as well:<br />
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];</p>
<p>thanks for any suggestions,<br />
josh
</p></description>
		</item>
		<item>
			<title>rfgsoftware on "BAD ACCESS"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19257#post-107941</link>
			<pubDate>Sat, 30 Jul 2011 12:57:40 +0000</pubDate>
			<dc:creator>rfgsoftware</dc:creator>
			<guid isPermaLink="false">107941@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi Guys,</p>
<p>I'm fairly new to this so apologise if this is a noob mistake.</p>
<p>I have an array of up 20 objects and I insert game objects in to this array.  I then loop through each of the array elements and call update on it and all works well.  When something meets a condition that should kill it I mark it as dead and clean it, then if necessary I re-use it's array slot and so on.  </p>
<p>In this example I create bullets with this code</p>
<p>gameObjects[nextFreePosition] = [[Bullet alloc] initBullet:@"bullet.png" xpos:position.x ypos:position.y data: gameData];<br />
gameObjects[nextFreePosition].currentXSpeed = [gameData getXVelocity: [player getFiringAngle]] * 100;<br />
gameObjects[nextFreePosition].currentYSpeed = [gameData getYVelocity: [player getFiringAngle]] * 100;<br />
gameObjects[nextFreePosition].name = @"bullet";<br />
[self addChild:gameObjects[nextFreePosition].representation];</p>
<p>In the update I cleanup objects and update live objects as follows</p>
<p>    for(int i=0;i&#60;20;i++)<br />
    {<br />
        if(gameObjects[i].isDead)<br />
        {<br />
            [self removeChild:gameObjects[i].representation cleanup:true];<br />
            [gameObjects[i] release]; //this has a destructor that cleans up inside<br />
            gameObjects[i] = NULL;<br />
        }<br />
        else if(gameObjects[i] != NULL)<br />
        {<br />
            [gameObjects[i] update:deltaTime];<br />
        }<br />
    }</p>
<p>game object dealloc looks like this<br />
-(void) dealloc<br />
{<br />
    [representation release];<br />
    [gameData release];</p>
<p>    [super dealloc];<br />
}</p>
<p>I have checked the contents of my array (gameObjects) and it's state is as I expect.  The problem is that after I cleanup the bullet from say position 5 I get a BAD_ACCESS error when updating gameObjects[0], which as far as I can tell I haven't touched.</p>
<p>I was wondering if anyone out there had any ideas why I  would get a bad access error on an object that still exists.</p>
<p>Thanks for your time.<br />
Regards<br />
Gary
</p></description>
		</item>
		<item>
			<title>michail on "How to deallocate particle system when it is done?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18450#post-103498</link>
			<pubDate>Thu, 07 Jul 2011 23:58:37 +0000</pubDate>
			<dc:creator>michail</dc:creator>
			<guid isPermaLink="false">103498@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>In particular, this involves removing it as a child from the scene when there are no more particles (and no more will be coming).</p>
<p>Also, should I expect poor performance if I keep allocating and deallocating particle systems?
</p></description>
		</item>
		<item>
			<title>guppieke on "Memory management best practice for interactive book"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9370#post-54047</link>
			<pubDate>Tue, 07 Sep 2010 11:14:21 +0000</pubDate>
			<dc:creator>guppieke</dc:creator>
			<guid isPermaLink="false">54047@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi guys,<br />
I'm creating an <strong>iPad</strong> application that's basically an interactive book. The users can flip through the pages and interact with the elements on a page.</p>
<p>Each page is a CCLayer and I go from page to page using a CCTransitionPageTurn.</p>
<p>I'm having memory issues since my pages contain a lot of content:<br />
* a background image (full screen)<br />
* some sprites<br />
* animations (I'm using SpriteFrameCache)<br />
* sounds</p>
<p>My app sometimes crashes due to low-memory problems (the console only outputs "Program received signal:  "0".") and this always happens when I go from one page to another. I get that having the 2 pages in memory at once can be memory-intensive but I was wondering how I can make sure I use my memory as optimal as possible. </p>
<p>What I'm doing now is the following:</p>
<p>* User flips the page<br />
* Clean up some heavy animations I no longer need (remove frames and textures)<br />
* Unschedule selectors<br />
* Do page turn transition<br />
* In onEnterTransitionDidFinish: add animations and textures for next page<br />
* In cleanup-method: remove unused sprite frames and textures</p>
<p>For cleaning up an animation I do the following:</p>
<p>[animation.frames removeAllObjects];<br />
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];<br />
[[CCTextureCache sharedTextureCache] removeTextureForKey:animationName];</p>
<p>I'm having the feeling that cleaning up the animations doesn't instantaneously free the memory.</p>
<p>So, my questions are:<br />
1) Does anyone know what the average memory limit is for an iPad app?<br />
2) Do you guys have some tips to improve my memory management<br />
3) Am I cleaning up my animations correctly? Is there a way to speed up the freeing of the memory?</p>
<p>thanks for the help!
</p></description>
		</item>
		<item>
			<title>URLArenzo on "Need advice."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18001#post-100959</link>
			<pubDate>Sat, 25 Jun 2011 10:15:14 +0000</pubDate>
			<dc:creator>URLArenzo</dc:creator>
			<guid isPermaLink="false">100959@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello. I am creating a simple game and I stuck in memory problems. I need an advice from more experienced programmers.<br />
In my game there would be two classes: player and enemy. Each of class would have about 10 animations with 12 frames.<br />
I do not know, how to store the images.<br />
How should I create animations?<br />
How would I release them?</p>
<p>Previously, I had two classes and inside each of class I was creating animations (for each unit of class there were 10 his own animations).<br />
Another problem is how to remove unwanted units of class to free up the memory. Each attempts to removeChild were only removing it from the layer, nothing more, memory was still consuming. </p>
<p>Please, give me some advices.<br />
Thank you!</p>
<p>Or maybe I should create only 10 animations for each class, and when I want to show them, just call them, [asprite runAction: animationAction];<br />
But there is another question, how to set one animation for multiple sprites?
</p></description>
		</item>
		<item>
			<title>URLArenzo on "Release CCAnimation"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17977#post-100856</link>
			<pubDate>Fri, 24 Jun 2011 17:24:43 +0000</pubDate>
			<dc:creator>URLArenzo</dc:creator>
			<guid isPermaLink="false">100856@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello, have not been here for a long time.<br />
And now I am facing the old and popular problem. Despite that it is popular problem, I have not found any useful and working solution for this problem.<br />
So, I want to release CCAnimation and free up the memory.<br />
Player.m</p>
<pre><code>playerWalkAnim = [CCAnimation animation];
    playerWalkAnim.name = @&#34;PlayerWalkAnim&#34;;
    for( int q=1;q&#60;12;q++){
        [playerWalkAnim addFrameWithFilename: [NSString stringWithFormat:@&#34;walkforward_%.2d.png&#34;, q]];
    }
    walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithDuration:1.5 animation:playerWalkAnim restoreOriginalFrame:NO]];
    [walkAction retain];</code></pre>
<p>so, this is how I create the animation. And now, the methods I have tried to release it and to free up the memory.<br />
<pre><code>-(void)destruct:(CCNode*)node{
    playerWalkAnim = nil;
    walkAction = nil;
    [playerWalkAnim release];
    [walkAction release];
//Nothing helped, and I try harder;
    [[CCDirector sharedDirector] purgeCachedData];
    [[CCTextureCache sharedTextureCache] removeAllTextures];
    [CCTextureCache purgeSharedTextureCache];
    [[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
    [CCSpriteFrameCache purgeSharedSpriteFrameCache];

    [[CCAnimationCache sharedAnimationCache]removeAnimationByName:@&#34;PlayerWalkAnim&#34;];</code></pre>
<p>I tried to name animation, to use removeAnimationByName:.<br />
I tried to purge sharedTextureCache.</p>
<p>Solving this issue, I have found some interesting information: creating animation, CCAnimationCache is empty; CCSpriteFrameCache is also empty, but CCTextureCache - is not. Removing all textures from the CCTextureCache does not free memory.</p>
<p>Now I think about removing textures using<br />
<pre><code>-(void) removeTexture: (CCTexture2D*) tex
-(void) removeTextureForKey:(NSString*)name</code></pre>
<p>but I do not know how to get the name of the texture, or how to get the texture at all.</p>
<p>Am I doing everything correct? I showed you the class Player : CCSprite. In the app, there would be about 10 units of the "Player". Is it correct to create animation for a unit inside a class? And how to properly remove the CCAnimation.</p>
<p>If it is possible, the source code showing how the memory should be freed by releasing CCAnimation would be appreciable.<br />
Thank you!
</p></description>
		</item>
		<item>
			<title>kingkong on "Memory Leak"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/16574#post-93466</link>
			<pubDate>Sat, 14 May 2011 23:51:20 +0000</pubDate>
			<dc:creator>kingkong</dc:creator>
			<guid isPermaLink="false">93466@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi Guyz,</p>
<p>I am programming my first game using Cocos2D for Ipad  worked just great was real quick to learn.<br />
I didnt faced Memory problem until i used Texture packer Sprite sheets (2048*2048)<br />
<code><br />
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"MenuSheet.plist"];<br />
</code><br />
and later on adding the Menu Btns as below<br />
<code><br />
CCSprite *_playBtn = [CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache]  spriteFrameByName:@"play.png"]];</p>
<p>CCSprite *_playBtnPressed = [CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"play_out.png"]];<br />
											playBtn = [CCMenuItemImage itemFromNormalSprite:_playBtn selectedSprite:_playBtnPressed<br />
			 target: self selector:@selector(playPressed:)];<br />
</code>		</p>
<p>Finally adding the Button to the MenuItem<br />
<code><br />
menu = [CCMenu menuWithItems:playBtn,nil];<br />
[self addChild:menu];<br />
</code></p>
<p>Once i replace the Scene inside dealloc<br />
<code><br />
[self removeChild:menu cleanup:YES];<br />
[[CCTextureCache sharedTextureCache] removeUnusedTextures];<br />
[[CCDirector sharedDirector] purgeCachedData];<br />
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];<br />
</code></p>
<p>I have lots of Images and a lengthy Animation with high quality png with  background of 1024*768 resolution </p>
<p>I am facing heavy usage of memory and memory leak even after using the exact code required for handling the Memory Management. </p>
<p>I am not able to figure out what am i missing in the above code. </p>
<p>In Advance Thanks </p>
<p>and best regards<br />
KK
</p></description>
		</item>
		<item>
			<title>littlejonnyninja on "Memory... Doing it so right, it crashes?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/15472#post-87724</link>
			<pubDate>Mon, 11 Apr 2011 23:39:06 +0000</pubDate>
			<dc:creator>littlejonnyninja</dc:creator>
			<guid isPermaLink="false">87724@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>So, my game is nearly complete.  So I tried running it using Leaks, and discovered lots of memory leaks.  I fixed most of them but there is one type of leak that seems to defy fixing.</p>
<p>This is the way my code was:</p>
<pre><code>@property (nonatomic,retain) GGPlasmaLauncher *plasmaLauncher1;
...
plasmaLauncher1 = [[GGPlasmaLauncher alloc] initWithAngle:0 andRadius:15 andFacing:0];

-(void) dealloc {
	[plasmaLauncher1 release];
	plasmaLauncher1 = nil;
...</code></pre>
<p>Works fine, but is reported as a leak, which I understand that due to the alloc and the retain in the property the plasmaLauncher1 gets a count of 2 and when the owner is dealloc'ed the count is still 1 so it is leaked.</p>
<p>So I changed the code to:<br />
<pre><code>@property (nonatomic,retain) GGPlasmaLauncher *plasmaLauncher1;
...
GGPlasmaLauncher *newPlasmaLauncher = [[GGPlasmaLauncher alloc] initWithAngle: 0 andRadius:15 and Facing:0];
plasmaLauncher1 = newPlasmaLauncher;
[newPlasmaLauncher release];</code></pre>
<p>Which from what I had read should have fixed the leak.  And maybe it did BUT....</p>
<pre><code>-(void) chargeWeapons {
	[plasmaLauncher1 charge];</code></pre>
<p>now fails with a bad memory access.</p>
<p>So... huh?  I'm sure as always it is something trivial that the objective c pros understand intuitively, but me... I'm confused.
</p></description>
		</item>
		<item>
			<title>litterbugkid on "Different behaviour between simulator and device, deallocing problem?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14465#post-81980</link>
			<pubDate>Sun, 13 Mar 2011 17:14:24 +0000</pubDate>
			<dc:creator>litterbugkid</dc:creator>
			<guid isPermaLink="false">81980@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have:<br />
1. Scene A replaced by Scene B<br />
2. When back button on Scene B is touched, is replaced by Scene A again.</p>
<p>Although when the back button is pressed on Scene B, Scene A shows but for some reason has the touch events Scene B has (although the graphics for Scene B are invisible). I've tried deallocing everything I can possibly find but on the device it makes no difference. On the simulator it has worked perfectly from the start.<br />
Is there anything I can try?
</p></description>
		</item>
		<item>
			<title>pfg2009 on "Many Actions and memory fragmentation"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/15155#post-86026</link>
			<pubDate>Fri, 01 Apr 2011 18:29:18 +0000</pubDate>
			<dc:creator>pfg2009</dc:creator>
			<guid isPermaLink="false">86026@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm noticing that I'm becoming a serious CCAction &#60;woman of loose morals&#62;.  I love the simplicity of the mechanism, the scripting quality, and the ease of use.  As a result, I create and destroy numerous actions through-out the course of an app.  So far, I haven't really seen any performance problems with this approach.  However, I don't fully understand how well / poorly the iOS manages frequent small object allocations and destructions.  So, the question is:</p>
<p>Should I build a repository and reuse actions when possible?  Or is this a completely un-necessary optimization that will just eat up permanent memory?</p>
<p>I'd hate to continue down this path only to be bit in the butt at the end.  Your thoughts are much appreciated!
</p></description>
		</item>
		<item>
			<title>asymptote on "allocate CCAnimation in separate thread and release in main."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12620#post-70876</link>
			<pubDate>Sat, 15 Jan 2011 05:56:17 +0000</pubDate>
			<dc:creator>asymptote</dc:creator>
			<guid isPermaLink="false">70876@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi</p>
<p>I am doing this in my Main Thread:</p>
<pre><code>CCAnimation *anim; //class variable

[NSThread detachNewThreadSelector:@selector(loadAimation) toTarget:self withObject:nil];</code></pre>
<p>In loadAimation:</p>
<pre><code>-(void) loadAimation {
    NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
        anim = [[CCAnimaton alloc] init];
        [autoreleasepool drain];
}</code></pre>
<p>And in main thread I release it:</p>
<p><code>[anim release];</code></p>
<p>Now I want to ask if this is fine regarding memory management.
</p></description>
		</item>
		<item>
			<title>dawc on "Problem with memory"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/7992#post-46606</link>
			<pubDate>Sat, 17 Jul 2010 15:25:43 +0000</pubDate>
			<dc:creator>dawc</dc:creator>
			<guid isPermaLink="false">46606@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Sorry for my poor English.</p>
<p>I'm new in Cocos2D and I have two problems with the memory management.<br />
1. I wrote an  application with two scenes, each with the  label, the menu and the picture, and I do not know how to release them(menu, label, picture). For example:</p>
<pre><code>- (void) dealloc
{
       [SpriteName release]
	[super dealloc];
}</code></pre>
<p> doesn't work.</p>
<p>2. Although the images are about 400kb, memory increases to 5Mb, and I have no idea why.</p>
<p>I will be grateful for help.</p>
<p>xCode Project:<br />
Mirror 1 :     <a href="http://www.mediafire.com/?3br311jb44nn2xg" rel="nofollow">http://www.mediafire.com/?3br311jb44nn2xg</a><br />
Mirror 2:      <a href="http://www.megaupload.com/?d=YO0W679K" rel="nofollow">http://www.megaupload.com/?d=YO0W679K</a></p>
<p>First Scene Code( Second scene is very similar )</p>
<p>.h</p>
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#60;Foundation/Foundation.h&#62;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;cocos2d.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;SecondScene.h&#34;

@interface FirstScene : CCLayer {
	CCSprite *image1;
}
+(id) scene;

@end</code></pre>
<p>.m</p>
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;FirstScene.h&#34;

@implementation FirstScene
+(id) scene
{
	CCScene *scene = [CCScene node];
	FirstScene *layer = [FirstScene node];
	[scene addChild: layer];
	return scene;
}

-(id) init
{
	if( (self=[super init] )) {
		// Image 1
		image1 = [CCSprite spriteWithFile:@&#34;image1.png&#34;];
		image1.position = ccp(160,170);
		[self addChild:image1]; 

		// Menu
		CCMenuItemImage *button1 = [CCMenuItemImage itemFromNormalImage:@&#34;button.png&#34; selectedImage:@&#34;button.png&#34; target:self selector:@selector(button1:)];
		CCMenu *menu = [CCMenu menuWithItems:button1, nil];
		[menu alignItemsVertically];
		menu.position = ccp(371, 158);
		[self addChild: menu];

		// Label
		CCLabel *label = [CCLabel labelWithString:@&#34;Next&#34; fontName:@&#34;Arial&#34; fontSize:30];
		label.position = ccp(362,162);
		label.color = ccc3(0,0,0);
		[self addChild: label];

	}
	return self;
}
-(void) button1: (id) sender {

	[[CCDirector sharedDirector] replaceScene:[CCFadeTransition  transitionWithDuration:0.5 scene:[SecondScene node]]];
}
- (void) dealloc
{

	[super dealloc];
}
@end</code></pre></description>
		</item>
		<item>
			<title>Drakeshe on "What do I need to release?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/11879#post-66968</link>
			<pubDate>Tue, 14 Dec 2010 13:12:38 +0000</pubDate>
			<dc:creator>Drakeshe</dc:creator>
			<guid isPermaLink="false">66968@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,<br />
Im at a loss. In my code I am drastically losing large amounts of memory when I'm creating and removing my dynamic objects. I cannot figure out where and why. Is there a list or something of a kind that can tell me what needs releasing and how to do it. </p>
<p>It gets very confusing when there are so many ways of releasing something, i'm often running into EXC_BAD_ACCESS.<br />
When there are so many ways such as[obj dealloc], [obj release], obj = nil, it gets confusing and some give errors. I ask of someone to please direct me.</p>
<p>Such an example of what I am doing is that I have an NSMutableArray of CCNodes. Each node has an NSMutableArray of sprites.<br />
These nodes are dynamically created, come on screen and then get removed after they leave the screen. I just have no idea of what I need to do to release them and their sprites properly.</p>
<p>Thanks in advance!<br />
Craig White
</p></description>
		</item>
		<item>
			<title>tallmystcarpet on "Yet an other memory management issue (linked to CCSpriteFrameCache)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/11257#post-63778</link>
			<pubDate>Fri, 19 Nov 2010 19:33:46 +0000</pubDate>
			<dc:creator>tallmystcarpet</dc:creator>
			<guid isPermaLink="false">63778@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I really thought that I understood all these memory management stuff!<br />
Well, apparently not!</p>
<p>Here's the code I'm using for using my CCSpriteFrameCache:<br />
<pre><code>@interface CreaSoldier : Char {
	CCSprite * sprite;
	CCAnimation *animAtt;
}

-(id) init{
	if ( (self= [super init]) ) {
		[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@&#34;MSsoldier.plist&#34;];
		CCSpriteSheet *spritesheet = [CCSpriteSheet spriteSheetWithFile:@&#34;MSsoldier.png&#34;];
		[self addChild:spritesheet];

		NSMutableArray *animFrameWalk = [NSMutableArray array];
		for(int i = 1; i &#60; 12; i++) {
			CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@&#34;creaAtt%d.png&#34;,i]];
			[animFrameWalk addObject:frame];		}
		animAtt = [[CCAnimation animationWithName:@&#34;att&#34; delay:0.12f frames:animFrameWalk] retain];

		sprite = [CCSprite spriteWithSpriteFrameName:@&#34;creaMove10.png&#34;];
		sprite.tag = 20;
		[spritesheet addChild:sprite];

                //Many other unrelated things
	}
	return self;
}

-(void) dealloc {
	[animAtt release];

	[super dealloc];
}</code></pre>
<p>First of all, do you see something wrong there ?</p>
<p>If I didn't retained animAtt in init, I was not able to use it outside init.<br />
So, I have to release it somewhere and obviously (or what I think to be obvious) is to do it twice in dealloc.<br />
If I do so, I got many errors which looks like : "CCSpriteFrameCache: removing unused frame: creaAtt12.png"</p>
<p>How can I handle this ?
</p></description>
		</item>
		<item>
			<title>plutovman on "suspect CCSpriteFrameCache  to cause &quot;Program received signal:  “0”.&quot; crash"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/10940#post-62249</link>
			<pubDate>Sat, 06 Nov 2010 22:31:47 +0000</pubDate>
			<dc:creator>plutovman</dc:creator>
			<guid isPermaLink="false">62249@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Greetings Cocos2D community.  </p>
<p>My app is generating the following error after a bit of play on the device:</p>
<p>Program received signal:  “0”.<br />
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")<br />
kill<br />
quit</p>
<p>The problem I'm having is that after a couple of pages, the application starts giving "Received memory warning. Level=1" messages which I suspect have to do with textures that are not being purged.  When I run on an ipad device, a few scenes in, the app crashes...splash!  When I run on the simulator, I get no memory warnings, no crashes...</p>
<p>I'm wondering if I share a bit of my game logic, I can get suggestions on what I'm not doing right.</p>
<p>I am developing a book-type app that basically uses a single scene whose elements are managed by a sqlite database.  When the user turns the page, I replace the scene with a different instance of the same scene that has a different set of assets gathered from the database.</p>
<pre><code>[[CCDirector sharedDirector] replaceScene: [curPageType scene]];</code></pre>
<p>I should add that each time I change scenes, I am loading a single 2048x2048 texture which I have processed with TexturePacker.<br />
Pixel format is set in the delegate:</p>
<pre><code>[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444];</code></pre>
<p>Here is how I load up my texture each time:</p>
<pre><code>//NSLog(@&#34;......loading pfile %@ &#34;, atlas_pfile);
			tex_layers = [[CCTextureCache sharedTextureCache] addImage:atlas_image];
			CCSpriteSheet *layers_spritesheet = [CCSpriteSheet spriteSheetWithFile:atlas_image];
			[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:atlas_pfile texture:tex_layers];
			[self addChild:layers_spritesheet];

			CCSprite *l1_sprite = [CCSprite spriteWithSpriteFrameName:l1_file];
			CCSprite *l2_sprite = [CCSprite spriteWithSpriteFrameName:l2_file];
			CCSprite *l3_sprite = [CCSprite spriteWithSpriteFrameName:l3_file];
			CCSprite *l4_sprite = [CCSprite spriteWithSpriteFrameName:l4_file];
			CCSprite *l5_sprite = [CCSprite spriteWithSpriteFrameName:l5_file];</code></pre>
<p>then, on my scene layer's onExit method, I deallocate them as follows:</p>
<pre><code>NSLog(@&#34;...removing unused junk, yo!&#34;);
	[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:atlas_pfile];
	[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromTexture:tex_layers];
	[[CCTextureCache sharedTextureCache] removeTexture:tex_layers];
	[[CCTextureCache sharedTextureCache] removeTextureForKey:atlas_image];  // probably don&#39;t need this one</code></pre>
<p>Also, I add this to the delegate's  applicationDidReceiveMemoryWarning:</p>
<pre><code>- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
		NSLog(@&#34;...purging cached data from receive memory warning, yo!&#34;);
		[[CCDirector sharedDirector] purgeCachedData];
		//[[CCTextureCache sharedTextureCache] removeAllTextures];
		//[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
	}</code></pre>
<p>Lastly, just to track where my app is failing, I add this to the scene's dealloc method:</p>
<pre><code>-(void) dealloc {
	//[self.layer release];
	//[_layer release];
	_layer = nil;
	self.layer = nil;

	NSLog(@&#34;...deallocating resources from scene, yo!&#34;);
	//[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
	//[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
	//[[CCTextureCache sharedTextureCache] removeUnusedTextures];

	[super dealloc];
}</code></pre>
<p>(yes, I've uncommented messages to sharedSpriteFrameCache and sharedTextureCache.  The app still fails when I remove these)</p>
<p>and here is the layer's dealloc method:</p>
<pre><code>- (void) dealloc
{
	NSLog(@&#34;...deallocating resources from layer, yo!&#34;);
	[self removeAllChildrenWithCleanup:TRUE];
	[self unschedule:@selector(tick:)];

	//[[CCTextureCache sharedTextureCache] removeTexture:tex_layers];
	[super dealloc];
}
@end</code></pre>
<p>Finally, here is the feedback from the debugger console</p>
<pre><code>Compile with -DNDEBUG defined to disable debug mode and runtime assertion checks
2010-11-06 13:49:25.170 BookTest7[18475:207] Received memory warning. Level=1
2010-11-06 13:49:25.176 BookTest7[18475:207] ...purging cached data from receive memory warning, yo!
2010-11-06 13:49:25.224 BookTest7[18475:207] cocos2d: deallocing &#60;CCTextureCache = 00222F70 &#124; num of textures =  13&#62;
2010-11-06 13:49:25.228 BookTest7[18475:207] Received memory warning. Level=1
2010-11-06 13:49:25.229 BookTest7[18475:207] ...purging cached data from receive memory warning, yo!
2010-11-06 13:49:25.231 BookTest7[18475:207] Received memory warning. Level=1
2010-11-06 13:49:25.233 BookTest7[18475:207] ...purging cached data from receive memory warning, yo!
2010-11-06 13:49:26.329 BookTest7[18475:207] ...removing unused junk, yo!
2010-11-06 13:49:26.339 BookTest7[18475:207] ...deallocating resources from scene, yo!
Program received signal:  “0”.
Data Formatters temporarily unavailable, will re-try after a &#39;continue&#39;. (Unknown error loading shared library &#34;/Developer/usr/lib/libXcodeDebuggerSupport.dylib&#34;)
kill
quit</code></pre>
<p>Tracing the app's "Real Memory" signature shows that it spikes up each time I load a scene, and then it quickly comes down, but not all the way, so that each time I load up a scene, I'm taking more and more memory. </p>
<p> Like I said, I suspect it has something to do with my use of sprites since I've got very little else going on.  However, I am also making a query to an sqlite database, I'm loading up a particle system, and using the chipmunk engine to do physics on a navigation sprite.   When I do "build and Analyze" I get a clean build, and I show no detectable leaks in instruments...</p>
<p>One last note that might be relevant.  I notice that while the scene's dealloc method is getting called every time, the layer's dealloc method is not.  Furthermore, when I run the app on the simulator and I quit the app, the layer's dealloc gets called a bunch of times...</p>
<pre><code>Compile with -DNDEBUG defined to disable debug mode and runtime assertion checks
2010-11-06 15:22:20.546 BookTest7[9509:207] ...removing unused junk, yo!
2010-11-06 15:22:20.547 BookTest7[9509:207] ...deallocating resources from scene, yo!
2010-11-06 15:22:27.338 BookTest7[9509:207] ...removing unused junk, yo!
2010-11-06 15:22:27.339 BookTest7[9509:207] ...deallocating resources from scene, yo!
2010-11-06 15:22:27.339 BookTest7[9509:207] ...deallocating resources from layer, yo!
2010-11-06 15:22:27.345 BookTest7[9509:207] ...deallocating resources from layer, yo!
2010-11-06 15:22:27.351 BookTest7[9509:207] ...deallocating resources from layer, yo!</code></pre>
<p>By contrast, when I quit the app running on the device, </p>
<pre><code>The Debugger has exited with status 0.</code></pre>
<p>Oh yes, and I'm using Cocos2d .99.4 with Xcode 3.2.3, and I'm doing all my testing directly on an ipad.</p>
<p>Thanks in advance for any ideas, and thanks everyone in general for such an awesome resource.  I've gotten quite a long way on my studies just from gleaning wisdom from this forum.
</p></description>
		</item>
		<item>
			<title>day on "Memory Leak in CCSprite?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4637#post-27599</link>
			<pubDate>Mon, 22 Feb 2010 10:22:29 +0000</pubDate>
			<dc:creator>day</dc:creator>
			<guid isPermaLink="false">27599@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have tried to use<br />
[ccspritesheet removeChild:sprite cleanup:YES]<br />
to remove the sprite and clean up.</p>
<p>But as I use the Performance Tool I see the memory didn't drop after remove.<br />
It keeps going up until the program crash...</p>
<p>How can i clean up the memory?</p>
<p>I have read a few post in the forum but none helps.</p>
<p>Please give me a hand~<br />
In a hurry......please help</p>
<p>Many thanks!
</p></description>
		</item>
		<item>
			<title>MikeSz on "Properly removing a spritesheet from BOTH TextureCache and SpriteFrameCache"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/8680#post-50308</link>
			<pubDate>Fri, 13 Aug 2010 17:55:56 +0000</pubDate>
			<dc:creator>MikeSz</dc:creator>
			<guid isPermaLink="false">50308@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm sure this must be really trivial but somehow I can't find the proper way ;)</p>
<p>So the situation is as follows:<br />
1) I don't want to run into insufficient texture memory problems<br />
2) Thus I create autoreleased scene for Tutorial<br />
3) Tutorial should have a few full-screen images, some buttons, maybe some animations<br />
a) Images for tutorial are completely separate from game images<br />
4) I want to add tutorial images to a spriteframecache, so it's easier to use any animations etc<br />
5) After checking tutorial - the scene should completely disappear from memory, including textures and spriteframes</p>
<p>Thus I do the following when creating a tutoial layer:<br />
<pre><code>CCTexture2D * tex = [[CCTextureCache sharedTextureCache] addImage:@&#34;tutorial_texture.png&#34;];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@&#34;tutorial_texture.plist&#34; texture:tex];</code></pre>
<p>Pretty self explanatory - I add a texture to TextureCache and SpriteFrames to SpriteFrameCache</p>
<p>Now I create some sprites, animations, etc</p>
<p>After leaving the scene it is dealloced (autoreleased) but the texture and sprite frames stay in the caches</p>
<p>I hope all is clear till now ;)</p>
<p>Now the time to remove the textures... I tried the following methods in the onEnter scene of menuscene, after exiting the tutorial layer. This is correct place to do it, I already checked it</p>
<p>1) [[CCTextureCache sharedTextureCache] removeUnusedTextures]; - tutorial texture is NOT removed, because it is used in the sprite frames<br />
2) [[CCTextureCache sharedTextureCache] removeTextureForKey:@"tutorial_texture.png"]; - again, NOT removed<br />
3) `<br />
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];<br />
[[CCTextureCache sharedTextureCache] removeUnusedTextures];<br />
`<br />
sprite frames are released and so is the texture. BUT ! all the other unused sprite frames are also immediately released, obviously not something I would like...</p>
<p>So how should I do it really ? Note that I only want to remove one large texture and all sprite frames that refer to it, nothing more</p>
<p>There is a function to add spriteframes from .plist file for a specific texture -addSpriteFramesWithFile:(NSString*)plist texture:(CCTexture2D*)texture</p>
<p>I really think there should be additional function which would do the very reverse - removeSpriteFramesFromFile:(NSString*) plist
</p></description>
		</item>
		<item>
			<title>Tiddlypeeps on "Memory management/ memory leaks"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/8942#post-51728</link>
			<pubDate>Mon, 23 Aug 2010 10:58:42 +0000</pubDate>
			<dc:creator>Tiddlypeeps</dc:creator>
			<guid isPermaLink="false">51728@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am trying to track down a memory leak in my cocos2D game. I have run the game using instruments to find what is causing the leaks and the bulk of the problem seems to come from this method.</p>
<p>[code]<br />
-(void)setColour:(int)c {</p>
<p>switch (c) {<br />
    case RED:</p>
<p>        images[SMALL_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"red_bubble_small.png"]];<br />
        images[SMALL_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"red_bubble_select_small.png"]];<br />
        images[LARGE_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"red_bubble.png"]];<br />
        images[LARGE_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"red_bubble_select.png"]];</p>
<p>        break;<br />
    case BLUE:</p>
<p>        images[SMALL_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"blue_bubble_small.png"]];<br />
        images[SMALL_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"blue_bubble_select_small.png"]];<br />
        images[LARGE_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"blue_bubble.png"]];<br />
        images[LARGE_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"blue_bubble_select.png"]];</p>
<p>        break;<br />
    case GREEN:</p>
<p>        images[SMALL_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"green_bubble_small.png"]];<br />
        images[SMALL_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"green_bubble_select_small.png"]];<br />
        images[LARGE_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"green_bubble.png"]];<br />
        images[LARGE_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"green_bubble_select.png"]];</p>
<p>        break;<br />
    case PURPLE:</p>
<p>        images[SMALL_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"purple_bubble_small.png"]];<br />
        images[SMALL_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"purple_bubble_select_small.png"]];<br />
        images[LARGE_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"purple_bubble.png"]];<br />
        images[LARGE_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"purple_bubble_select.png"]];</p>
<p>        break;<br />
    case YELLOW:</p>
<p>        images[SMALL_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"yellow_bubble_small.png"]];<br />
        images[SMALL_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"yellow_bubble_select_small.png"]];<br />
        images[LARGE_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"yellow_bubble.png"]];<br />
        images[LARGE_SELECTED_BUBBLE_IMAGE] = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:(NSString *)@"yellow_bubble_select.png"]];</p>
<p>        break;</p>
<p>}</p>
<p>[images[SMALL_BUBBLE_IMAGE] retain];<br />
[images[SMALL_SELECTED_BUBBLE_IMAGE] retain];<br />
[images[LARGE_BUBBLE_IMAGE] retain];<br />
[images[LARGE_SELECTED_BUBBLE_IMAGE] retain];</p>
<p>[small_bubble setTexture:images[SMALL_BUBBLE_IMAGE]];<br />
[large_bubble setTexture:images[LARGE_BUBBLE_IMAGE]];</p>
<p>colour = c;</p>
<p>}</p>
<p>[/code]</p>
<p>images is an array of CCTexture2D's.<br />
All this function does is change the images used by an object, each object has 4 images associated with it so I store them in an array. I had thought that any pointers I use that are not retained were released automatically, but then i figured maby this wasn't the case. The project would crash on me if I called release on the object without having first called retain on the object so that's why the lines retaining the images are there.</p>
<p>I call these lines in the dealloc function;</p>
<p>[code]<br />
[images[SMALL_BUBBLE_IMAGE] release];<br />
[images[SMALL_SELECTED_BUBBLE_IMAGE] release];<br />
[images[LARGE_BUBBLE_IMAGE] release];<br />
[images[LARGE_SELECTED_BUBBLE_IMAGE] release];<br />
[/code]</p>
<p>Instruments tells me the lines within the case statement are where the memory leaks are. This function is only called once in an objects life cycle. Any ideas why this is causing memory leaks?
</p></description>
		</item>
		<item>
			<title>NickFalk on "CCLayer vs. CCScene somewhat confused"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/7858#post-45961</link>
			<pubDate>Tue, 13 Jul 2010 04:17:26 +0000</pubDate>
			<dc:creator>NickFalk</dc:creator>
			<guid isPermaLink="false">45961@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Actually I haven't really thought about this until recently as I've been struggling with problems releasing my nodes, anyway:</p>
<p>According to the documentation the CCScene class is the one to use for the different "parts" of the game. (Gameview, menus, highscorescreen etc.).</p>
<p>Yet, from the examples I find it seems to me they are most commonly defined as CCLayers? Am I completely bonkers? I've defined them as CCLayers myself. My model is one where I let the AppDelegate handle the actual scene/layer-switching (through notifications). However when I run replaceScene: the active layer is certainly not released, although the new one <em>is</em> pushed to the front...<br />
<pre><code>-(void) switchToLowScoreListFromNewScore{
	[NewLowScore release];
	[[CCDirector sharedDirector] replaceScene: [LowScoreList scene]];
}</code></pre>
<p>Yes, I am aware that the first release call shouldn't be necessary but a desperate man does desperate things. ;) Anyway, it doesn't take anyway, clearly I'm missing something obvious...
</p></description>
		</item>
		<item>
			<title>Wayfarer on "Some Questions about CCCallFuncN"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/7876#post-46026</link>
			<pubDate>Tue, 13 Jul 2010 15:29:36 +0000</pubDate>
			<dc:creator>Wayfarer</dc:creator>
			<guid isPermaLink="false">46026@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>So, in my code I have a method that spawns an asteroid.  Hurray!</p>
<pre><code>- (void)spawnAsteroid {
	Asteroid *ast = [Asteroid initWithAsteroid];
	ast.tag = 3;
	int x = arc4random() % 480;
	CGPoint endPos = CGPointMake(x, -10);
	[ast runAction:[CCSequence actions:
					 [CCMoveTo actionWithDuration:4.0 position:endPos],
					 [CCCallFuncN actionWithTarget:self
										  selector:@selector(spriteDone:)],
					 nil]];
	[self addBoxBodyForSprite:ast];
	[self.parent addChild:ast];
}</code></pre>
<p>I am using Box2D for my Collision Detection, hence the "addBoxBody..." method there at the end.  But in another method, I'm having some issues with memory management, so I want to ask some clarifying questions.  In my  runAction call here, I have it do:</p>
<p><code>[CCCallFuncN actionWithTarget:self selector:@selector(spriteDone:)]</code></p>
<p>This runs after the first CCMoveTo is over.  But what if the asteroid doesn't reach the end of the move to?  I can blow up asteroids, in which case they are removed (RemoveChild), so does that method ever run?  Does spriteDone Method get called?
</p></description>
		</item>
		<item>
			<title>Bongeh on "Layer not deallocing, but others that are also children of the same scene are???"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/6938#post-40738</link>
			<pubDate>Tue, 08 Jun 2010 13:38:29 +0000</pubDate>
			<dc:creator>Bongeh</dc:creator>
			<guid isPermaLink="false">40738@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey guys, ive got a very peculiar bug appear today.</p>
<p>I've been working on my project a long time now, and i must have added something today to cause this..</p>
<p>Basically, i have a <code>CCScene</code> called <code>GameScene</code></p>
<p><code>GameScene</code> has 2 children, <code>HUDLayer</code> and <code>GameLayer</code> </p>
<p>The problem is, <code>GameLayer</code> is not deallocating. I have an NSLog in <code>[GameLayer dealloc]</code>, the method never gets called. It means that when you loose, if you go back into the level, it crashes because it says you can't add the same child twice.</p>
<p>Very very rarely, it does deallocate. </p>
<p>What would stop a Layer from deallocating, perhaps I have a retained child of that layer somewhere?</p>
<p>My Control layer's dealloc method </p>
<pre><code>- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// don&#39;t forget to call &#34;super dealloc&#34;

	NSLog(@&#34;control layer dealloc called&#34;);
	[_mapsheet removeAllChildrenWithCleanup:YES];
	[self removeChild:_mapsheet cleanup:YES];
	_mapsheet = nil;

	[_mapsheetNonAlpha removeAllChildrenWithCleanup:YES];
	[self removeChild:_mapsheetNonAlpha cleanup:YES];
	_mapsheetNonAlpha = nil;

	cpSpaceFreeChildren(_gameSpace);
	cpSpaceFree(_gameSpace);
	_gameSpace = nil;
	NSLog(@&#34;gamespace purged???&#34;);
	[_movingSprites release];
	_movingSprites = nil;
	[self removeAllChildrenWithCleanup:YES];
	[super dealloc];
}</code></pre>
<p>This does not get called though..
</p></description>
		</item>
		<item>
			<title>ashmira on "Memory leaking"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/6382#post-37305</link>
			<pubDate>Thu, 13 May 2010 06:51:24 +0000</pubDate>
			<dc:creator>ashmira</dc:creator>
			<guid isPermaLink="false">37305@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>i got a problem with this coding where it got leak. i already release but still leaking. anybody can help?<br />
<pre><code>sword2 = [[items alloc] initWithName:@&#34;Double Sword&#34; description:@&#34;Kill Faster&#34; image:@&#34;sword2a.png&#34; statHP:20 statMP:20 statInt:1 statStr:2 damage:20 Ldamage:10 defence:10 type:3 level:1];
sword2.sell = 1700;</code></pre>
<p>  release in dealloc<br />
<pre><code>[sword2 release];
sword2=nil;</code></pre></description>
		</item>
		<item>
			<title>mac_55 on "Best Practices help"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/5395#post-32246</link>
			<pubDate>Tue, 30 Mar 2010 23:22:16 +0000</pubDate>
			<dc:creator>mac_55</dc:creator>
			<guid isPermaLink="false">32246@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi guys,</p>
<p>I've read the piece on the wiki about best practices, and that all makes perfect sense. There's a couple of things I'm unclear of though, I hope you can help!</p>
<p>Sprites / Labels: I'm adding these to the screen in the init method of my scene. What's the best way to manage these for most efficient memory useage bearing in mind that I need to refer to these to update them? Before, I was getting the child of the layer by tag, casting it to a sprite or label, and then updating it. Is this method better or worse than declaring a CCLabel in the header file for the scene and assigning it when my label is added to the layer?</p>
<p>In my head, I imagine that finding the child, casting it to a type and then updating it will use more memory than simply keeping a reference to it in the class?</p>
<p>My second question is that I've noticed a pretty drastic drop in frame rate when I tap on the screen in my scene. I have 3 objects on the screen - a ball (a sprite that doesn't really do anything), and 2 progress timers. The values for these bars are stored in a singleton class. On touch, I'm updating their values and then calling an action on the Progress Timer which animates to it's new position.</p>
<p>I've noticed a drop in framerate from around 59.0FPS to around 20FPS for about 0.5 seconds, then it creeps back to 59.0FPS. I've turned off thumb compilation and I've tried compiling in release mode (for 3.0 SDK), which provides a bit of a framerate boost.</p>
<p>Is my problem just with the NSLogs used in debug? or do I need to be concerned that adding a few more sprites is going to kill my game? It runs in the simulator at 60FPS</p>
<p>Here's my code:<br />
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event<br />
{<br />
	UITouch *touch = [touches anyObject];</p>
<p>	if( touch ) {<br />
		CGPoint location = [touch locationInView: [touch view]];</p>
<p>		// IMPORTANT:<br />
		// The touches are always in "portrait" coordinates. You need to convert them to your current orientation<br />
		CGPoint convertedPoint = [[CCDirector sharedDirector] convertToGL:location];</p>
<p>		player.targetx = convertedPoint.x;<br />
		player.targety = convertedPoint.y;</p>
<p>		//Increase HP by 10 points<br />
		gamestate.player.CurrentHP -=10; // Gamestate is my singleton<br />
		gamestate.player.CurrentMP -=20;</p>
<p>		float HPpercent = ((float)gamestate.player.CurrentHP / (float)gamestate.player.MaxHP) *100;<br />
		float MPpercent = ((float)gamestate.player.CurrentMP / (float)gamestate.player.MaxMP) *100;</p>
<p>//progress and mpprogress are Progress Timer objects which are children of the layer and a reference is kept within the scene's class<br />
		[progress runAction:[CCRepeat actionWithAction:[ProgressFromTo actionWithDuration:0.5f from:[progress percentage] to:HPpercent] times:1]];<br />
		[mpprogress runAction:[CCRepeat actionWithAction:[ProgressFromTo actionWithDuration:0.5f from:[mpprogress percentage] to:MPpercent] times:1]];<br />
	}<br />
}</p>
<p>Thanks!
</p></description>
		</item>
		<item>
			<title>SwizzerSweet on "Memory Management Question"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/5000#post-29840</link>
			<pubDate>Fri, 12 Mar 2010 17:06:12 +0000</pubDate>
			<dc:creator>SwizzerSweet</dc:creator>
			<guid isPermaLink="false">29840@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I don't know if this is objective C / Cocos2D specific, and if it is objective C, maybe someone could tell me the ideal forum to ask that question?</p>
<p>This is just a function to test if a board is clear, and I'm creating a pointer and setting it to whichever cell we're checking. The object in the boardArray is a Block which subclasses CCSprite.</p>
<p>Heres the code:</p>
<p>-(bool)boardCleared {<br />
	for (int i = 0; i &#60; 8; i++) {<br />
		for (int j = 0; j&#60;8; j++) {<br />
			Block * blocko = [[boardArray objectAtIndex:i] objectAtIndex:j];<br />
			if (blocko.blockType != 0) {<br />
				return NO;<br />
			}<br />
		}<br />
	}<br />
	return YES;<br />
}</p>
<p>The question is, is the pointer blocko need to be released? Or does it not count.</p>
<p>Thanks
</p></description>
		</item>
		<item>
			<title>swoot on "fps problems when overlapping gui elements on a spritesheet"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4396#post-26213</link>
			<pubDate>Wed, 10 Feb 2010 15:17:45 +0000</pubDate>
			<dc:creator>swoot</dc:creator>
			<guid isPermaLink="false">26213@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey, </p>
<p>I have a slight problem with a project I'm working with. For starters I'll throw in the background info.<br />
I'm using cocos2d v0.99.0-rc, iPhone SDK 3.1.2 and mostly the Simulator (occasionally a old iPod Touch,<br />
naturally at 3.1.2 firmware). I run the game mostly in Debug mode, on the Simulator and the iTouch.</p>
<p>How the game is setup:<br />
-1 Scene<br />
-1 Layer (created by the scene)<br />
	-BoardLayer (has 70 TileSprites + background + gui/hud)<br />
- 70 TileSprites (saved in a SpriteSheet and all use the spriteSheetRendering)<br />
	-TileSprites are randomly generated<br />
-Screenshot: <a href="http://dl.dropbox.com/u/816458/screenie.png" rel="nofollow">http://dl.dropbox.com/u/816458/screenie.png</a><br />
-Source: <a href="http://dl.dropbox.com/u/816458/TestCase.zip" rel="nofollow">http://dl.dropbox.com/u/816458/TestCase.zip</a> (graphics are placeholders, but cause the same problem<br />
	as with the normal ones)</p>
<p>The BoardLayer consist of a background image which is a child of the Layer, and the background image has a<br />
SpriteSheet as a child. We add Tiles to the SpriteSheet and then scroll the background so the tiles scroll<br />
with the background aswell.</p>
<p>So what is the problem? FPS... as showed in the screenshot, the FPS is rather low (in debug mode AND release).<br />
So any optimization tips are welcomed with open arms and a cheery smile! What I've tested so far is I turned<br />
off the "Compile for Thumb" option in the project since I found some reference to that on these forums<br />
(<a href="http://www.cocos2d-iphone.org/archives/26" rel="nofollow">http://www.cocos2d-iphone.org/archives/26</a>). Though this does not help the Simulator, I do get a noticeable<br />
upgrade in FPS on the iTouch device (around 40 to 50fps).</p>
<p>The cause for the FPS drop, atleast the reason I suspect, is the GUI/HUD (the borders). Since one way to get<br />
better fps is to disable the GUI (can be done by commenting out [self initGUI]; call from BoardLayer's init),<br />
so this way you get a constant 60fps. I first thought the problem was that I was using one picture for the<br />
borders (guiframe1.png in the src, has just borders and the middle is alphaed out) but I tried with 4 pieces<br />
(left, right, bottom and top) as the borders and still got the same FPS decrease. Second thing I tried was<br />
to add every sprite into one file (the source is for this) but that didn't give any FPS boost over the previous<br />
way of having two layers, one for the board and one for the GUI/HUD.<br />
I'm a starting game developer so I'm a wee bit clueless on some rendering (atleast OpenGL ES is a new friend for<br />
me) stuff so do correct me if I'm wrong here, but I assume everything is drawn, not just the visible stuff.<br />
I mean the i.e. the background bits behind the Tiles, possible Tiles behind the GUI's borders etc? </p>
<p>Another question that came into mind is, can you create different sized layers? Considering the screenshot<br />
again and the bit with the groovy bright Tiles (the Board), could that be made as a smaller layer (sized<br />
290x408) and just updating stuff there? Mmm, with updating I mean that those Tiles are supposed to scroll down<br />
with the background (which will be around 290x2000 in size later). Also, which is a better idea, scroll every<br />
tile on its own with CCMoveBy or have them as the child of the background and moving just the background (currently<br />
would be done like this?</p>
<p>Also, memory management... if I have a CCLayer (BoardLayer), which has a CCSprite (background image) as a child,<br />
which has a CCSpriteSheet as a child AND that thing has like 70 TileSprites as children... what is the correct<br />
order in releasing these? Been mostly using Java and Python so I'm still learning correct memory management,<br />
thus needing to ask that question, since children freak me out when doing memory management :) I suppose I just<br />
need to release the parent, and that will deal with the kids? Or do I need to release everything by hand?</p>
<p>A lot of questions from an information hungry person :)</p>
<p>Cheers, </p>
<p>Pete
</p></description>
		</item>

	</channel>
</rss>

