Cocos2D Scene Release

When exactly is the Cocos2D scene dealloc method called? Right, when is another scene loading? Or after the scene has finished loading?
Also, what should be in the dealloc method if I plan to overwrite it?
Cocos2D automatically remove all nodes attached to the scene when the scene is freed. However, if I plan to rewrite it, in particular, what methods should I name? So, how can I manage my scene to make sure they leak free, 100%? Thanks in advance!

+4
source share
2 answers

The CCScene Liberator follows the same rules as any other object. It will work when the reference count for CCScene reaches zero.

The default scene does not care about another, which is about to replace it, but if you change the scene with a transition, there will be a period of time when two scenes exist simultaneously. When the transition is completed, the transition will release its link to the first scene, which is likely to be the last such link, and the first scene will be released.

In your scene de-locator, put CCLOG to see when it starts. I put one in each to make sure.

In the general case, manually release any object created using a method starting with alloc , new or copy , whether it is a Cocos2D object or otherwise. Other creation methods, such as Cocos2D node , do not require a manual version if you yourself did not select the retain object manually, which may be useful if you are not going to add it as a child to another node immediately.

As you said, adding node as a child of another does not mean that it needs an additional release ; Cocos2D will work with this.

+1
source

Each object that you select in your scene class that is not added to the scene as a child must be explicitly released.

The scene is freed (and most of the time freed if you have not saved it somewhere else) when you replace it (using the replaceScene method) with another scene object or place it from the scene stack.

It is always advisable to look in the source code (which contains very useful comments) and find out what exactly needs to be done if you customize your scene class.

+1
source

Source: https://habr.com/ru/post/1416043/