The situation is as follows:
On the in-game combat page, the victory window is displayed. Click the next button in the window to switch to the resource loading scenario,
At this time, the game is paused, and all ccactions are paused. When switching a scenario, there are ccactions in the combat scenario.
If not, a reference of the CCAction object is still held. If the reference value is not 0 after the scenario is switched, memory leakage occurs.
Define the lifecycle of each Scene. Its parent class is as follows:
#ifndef SCREEN_H#define SCREEN_H#include "cocos2d.h"using namespace cocos2d;namespace giant {class Screen : public CCScene {protected:int m_width;int m_height;protected:Screen(int width, int height);public:virtual void show() = 0;virtual void close() = 0;virtual void pause() = 0;virtual void resume() = 0;};}#endif
Call show () to initialize resources when game scenarios enter
The game suspends pause () and suspends updates in the scenario, including CCAction
Call resume () to resume all previously paused updates.
Game scenario exit call close (), destroy view, release memory
Execute the following code when calling pause:
m_pActionSet = CCDirector::sharedDirector()->getActionManager()->pauseAllRunningActions(); m_pActionSet->retain();
Run the following code when calling resume:
CCDirector::sharedDirector()->getActionManager()->resumeTargets(m_pActionSet); m_pActionSet->release();
Execute the following code when calling close:
CCActionManager *pActionManager = CCDirector::sharedDirector()->getActionManager(); CCSetIterator iter; for (iter = m_pActionSet->begin(); iter != m_pActionSet->end(); ++iter) { pActionManager->removeAllActionsFromTarget(*iter); } m_pActionSet->release();
You can release references in CCAction through the action in close ().