c++ - Why doesn't removing the last scene in cocosd2d-x trigger the scenes destructor? -
i've added player* _player
pointer helloworldscene
scene in cocos2d-x v.2.2.2. i've defined class player : public cocos2d::object
, it's referenced counted. create method helloworldscene
looks
scene* helloworldscene::createscene(player* player) { auto scene = scene::create(); auto layer = helloworldscene::create(); layer->_player = player; player->retain(); scene->addchild(layer); return scene; }
where player
instantiated in appdelegate::applicationdidfinishlaunching()
. now, since i've retained _player
(and feel nice guy today), i've decided release well:
helloworldscene::~helloworldscene() { if (_player) { _player->release(); } }
so far good. however, when helloworldscene
popped, following called
void director::popscene(void) { ccassert(_runningscene != nullptr, "running scene should not null"); _scenesstack.popback(); ssize_t c = _scenesstack.size(); if (c == 0) { end(); } else { _sendcleanuptoscene = true; _nextscene = _scenesstack.at(c - 1); } }
so, whenever helloworldscene
last scene in stack, won't destroyed? (at least that's seems xcode.)
i'm not c++ grandmaster, forgive ignorance. yet, me, quite unexpected behavior. shouldn't popped scene cleaned before program termination (by letting _sendcleanuptoscene = true
, having run 1 more iteration)?
clearly, i'm missing ... if shed light on this, i'd thrilled! :)
so premise of question wrong - somehow got idea had released @ program termination. but, re-learned yesterday, os of course reclaim allocated memory once program terminates. making releasing last scene in stack unnecessary.
Comments
Post a Comment