Sergey Shambir wrote:
There are two ways to fix issue: refactoring which sanitizes code and direct tracing.
The first way is to make all nodes to use clean CCNode lifecycle:
# C++ constructor sets all raw pointers and numbers to 0 (but it’s better to have smart pointers which automatically init nested pointer with 0)
init[...]([...]) creates children nodes and attaches them to this node
onEnter() turns on actions, scheduled methods, scheduled update, touch/keypad/IME event subscriptions
onExit() stops all actions, scheduled methods, scheduled update, touch/keypad/IME event subscriptions
cleanup() finally removes node from own arrays/dictionaries for remove all links to it, so after calling
cleanup() parent will remove object from own dictionary
m_children which should be the last link to node, node will be deleted.
Second way includes a little or a big tweak in CCNode sources: create global static variable in
CCNode.cpp which will keep an
std::set of living nodes, modify this array from CCNode constructor and destructor. You’ll also need IDE which can display content of
std::set in debugger (QtCreator, probably Visual Studio and XCode can do it).
We’ve used more complex approach: added method which collects functions stack trace at given point and stored stacktrace each time when retain/release was called for CCNode, so we’ve seen who keeps link to node.
Thanks for your replay!
I doing all this things but still have a problem with memory
Can I provide you an example of what I do and maybe you will have some time to explain me where is my mistake? Please.
class CCSomeClass : public CCSprite
CCSomeClass(/** Maybe some params */);
static CCSomeClass* create(/** Maybe some params */);
this->removeAllChildrenAndCleanup(true); // Or this->cleanup(); Does't matter.
CCSomeClass::CCSomeClass(/** Maybe some params */) :
CCSprite(/** Maybe some params */),
// Do some stuffs.
CCSomeClass* CCSomeClass::create(/** Maybe some params */)
CCSomeClass* cl = new CCSomeClass(/** Maybe some params */);
cl->retain(); // Use retain here for access this object if I need it and really don't forget to call release() after this object don't need me more.
this->scheduleUpdate(); // Need it for use update(float deltaTime); method;
So after this object no need me no more and I release it by calling release(); or CC_SAFE_RELEASE(); the texture it “hold” is unloading but memory are not
Where is my mistake? Please help me. Thanks!