AutoreleasePool?

I have read this part (it is a very good tutorial): http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_7_~~*Some_Icing_on_the_Cake
Where it says this:
<pre>
Port Tips

  1. Pay attention to GameOverLayer.*label and GameOverScene._layer, they are declared in objc with @property , it means that they are retained, so they should be released in dealloc. Similarly, there is retain in init of GameOverLayer and GameOverScene, and release should be called in GameOverLayer\ andGameOverScene respectively.
  2. NSAutoReleasePool is also ported in cocos2d-x. This Garbage Collector is good for c++ programming, and the utility is the same as in iOS, more information refers to http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html.
    In cocos2d-x, we should call release in two cases:
    • The object is newed by ourself, for example, CCSprite sprite = new CCSprite;
    • The object is created by a static function, for example, CCSprite
    sprite = CCSprite::spriteWithFile, in this case, we don’t need to release, but when sprite~~>retain() is called, then sprite->release() should be called too.
What is “retain”? How it works and where can i read more about the property of the objects? How NSAutoreleasePool works? If i use this thing i dont have to release all objects in the dealloc module? Is it safe to use? Why it says we have to release newly created objects? It doesn’t have sense to me… if you create one object, why wouldu you want to release it instantly?

Hi,

If a CCObject or its subclass has invoked autorelease(), then you don’t do retain , you needn’t call the release function.

• The object is newed by ourself, for example, CCSprite *sprite = new CCSprite();
• The object is created by a static function, for example, CCSprite *sprite = CCSprite::spriteWithFile(...), in this case, we don’t need to release, but when sprite->retain() is called, then sprite->release() should be called too.

I think you can refer http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-BAJHFBGH.

So basically is better to “manually” release/reatain objects right?

Yes, as possible as you can.