<?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; Topic: What to clean up when loading a new level in your game?</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/4266</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 02:19:26 +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/topic/4266" rel="self" type="application/rss+xml" />

		<item>
			<title>abitofcode on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-26009</link>
			<pubDate>Mon, 08 Feb 2010 21:52:48 +0000</pubDate>
			<dc:creator>abitofcode</dc:creator>
			<guid isPermaLink="false">26009@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Between levels you may not want to remove all your textures using </p>
<pre><code>[[TextureMgr sharedTextureMgr] removeUnusedTextures];</code></pre>
<p>but just the ones that are level specific as discussed here <a href="http://www.cocos2d-iphone.org/forum/topic/4245" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/4245</a>
</p></description>
		</item>
		<item>
			<title>oscarmk on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-26007</link>
			<pubDate>Mon, 08 Feb 2010 21:37:05 +0000</pubDate>
			<dc:creator>oscarmk</dc:creator>
			<guid isPermaLink="false">26007@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thank you mobilebros.
</p></description>
		</item>
		<item>
			<title>mobilebros on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-26000</link>
			<pubDate>Mon, 08 Feb 2010 20:39:09 +0000</pubDate>
			<dc:creator>mobilebros</dc:creator>
			<guid isPermaLink="false">26000@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/5359'>oscarmk</a> - Just free all the objects in the space, and then the space itself</p>
<pre><code>cpSpaceFreeChildren(_space);
cpSpaceFree(_space);</code></pre></description>
		</item>
		<item>
			<title>oscarmk on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-25968</link>
			<pubDate>Mon, 08 Feb 2010 15:03:31 +0000</pubDate>
			<dc:creator>oscarmk</dc:creator>
			<guid isPermaLink="false">25968@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>So what about chipmunk?, how do I free all the objects and the space?
</p></description>
		</item>
		<item>
			<title>oscarmk on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-25597</link>
			<pubDate>Fri, 05 Feb 2010 14:55:12 +0000</pubDate>
			<dc:creator>oscarmk</dc:creator>
			<guid isPermaLink="false">25597@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/3544'>lyeandro2587</a>: Thank you for your input, yes I am aware that I need to release anything that is retained by something else than the layer. As I believe Layers work pretty much like UIView in the sense than when they are deallocating anything they are retaining with retain count of 1 is deallocated.</p>
<p>@<a href='http://www.cocos2d-iphone.org/forum/profile/1750'>hactar</a>: My mistake i actually wanted to say replace Scene, I do know the difference. Thank you I will try that NSLog to maek sure it is going to be deallocated.</p>
<p>@<a href='http://www.cocos2d-iphone.org/forum/profile/1037'>David994A</a>: Yes that is where I am calling it, Is that the best practice?</p>
<p>So what about the chipmunk objects what do you have to do to release all of those?. Right know I am doing to remove an object when it is no longer needed this 4 lines although I am not sure you actually need all those 4...</p>
<pre><code>cpSpaceRemoveBody(space, objectBody);
		cpBodyFree(objectBody);
		cpSpaceRemoveShape(space, objectShape);
		cpShapeFree(objectShape);</code></pre>
<p>I think you really only need to free them or do you have to remove them first too?</p>
<p>I know there is cpRemoveAllChildren or something of the sort and cpSpaceFree is that what you need to call before to clean up all chipmunk objects?
</p></description>
		</item>
		<item>
			<title>napierzaza on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-25596</link>
			<pubDate>Fri, 05 Feb 2010 14:51:41 +0000</pubDate>
			<dc:creator>napierzaza</dc:creator>
			<guid isPermaLink="false">25596@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Doesn't it still retain textures from the first level unless you clear them? That's my experience, mind you, it could be good for you.
</p></description>
		</item>
		<item>
			<title>David994A on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-25571</link>
			<pubDate>Fri, 05 Feb 2010 03:57:42 +0000</pubDate>
			<dc:creator>David994A</dc:creator>
			<guid isPermaLink="false">25571@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>It seems that you would want to call [[TextureMgr sharedTextureMgr] removeUnusedTextures]; at the start of a new scene using the -(void) onEnterTransitionDidFinish; method
</p></description>
		</item>
		<item>
			<title>hactar on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-25558</link>
			<pubDate>Fri, 05 Feb 2010 01:47:44 +0000</pubDate>
			<dc:creator>hactar</dc:creator>
			<guid isPermaLink="false">25558@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>PS: a great way to see when and how dealloc works is simply adding NSLog(@"dealloc called!"); to your dealloc method. If for some reason you find an object is not being dealloced as expected, add this code to the object/scene/whatever that is not being dealloced:</p>
<pre><code>- (oneway void)release
{
	NSLog(@&#34;Object retain count will become: %d&#34;, [self retainCount] -1);
	[super release];
}</code></pre>
<p>This will show you your retain count whenever this object gets a release message and so will help you see just how many objects are retaining your object.
</p></description>
		</item>
		<item>
			<title>hactar on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-25556</link>
			<pubDate>Fri, 05 Feb 2010 01:41:38 +0000</pubDate>
			<dc:creator>hactar</dc:creator>
			<guid isPermaLink="false">25556@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Oscarmk, read up on the difference between pushScene and replaceScene, because pushScene is not going to do what you expect it to do.</p>
<p>replaceScene will call a release on your level 1 scene. Assuming there is nothing else retaining your level 1 scene then your scene dealloc method will be called, and so anything you release there will also be released.</p>
<p>Once your old scene is completely removed then you can run  [[TextureMgr sharedTextureMgr] removeUnusedTextures]; Careful when using transitions, as calling removeUnusedTextures during a scene transmission will not remove the old scenes textures: these are still in use. I suggest using instruments to measure if unusedTextures is actually removing anything. It took me a while to find the correct spots to call it in my code.
</p></description>
		</item>
		<item>
			<title>lyeandro2587 on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-25549</link>
			<pubDate>Fri, 05 Feb 2010 01:07:29 +0000</pubDate>
			<dc:creator>lyeandro2587</dc:creator>
			<guid isPermaLink="false">25549@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I still think you need to release all declared retained objects.
</p></description>
		</item>
		<item>
			<title>oscarmk on "What to clean up when loading a new level in your game?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4266#post-25537</link>
			<pubDate>Thu, 04 Feb 2010 22:56:44 +0000</pubDate>
			<dc:creator>oscarmk</dc:creator>
			<guid isPermaLink="false">25537@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello,</p>
<p>So let's say the user completed level 1 of your game, and now you are about to present a level 2 to the user. What do you have to clean up assuming you are using chipmunk?.</p>
<p>As far as I understand cocos2d when you call pushScene to go to your next level, I assume you first have to free all the chipmunk objects, and then the Scene automatically releases all of its retained objects and calls dealloc?. is this correct?.</p>
<p>Also once your new Scene/level is loaded you should also call [[TextureMgr sharedTextureMgr] removeUnusedTextures]; is this correct?</p>
<p>Thank you.</p>
<p>-Oscar
</p></description>
		</item>

	</channel>
</rss>

