When I’ve checked the caller of Director::purgeCachedData() in the cocos2dx engine, no caller were found and It means nobody call this function at all !
My question is about The situations which I may need call this function to free my memory. Maybe … : 1. Layer::Destructors ? 2. Layer::OnExit ?? 3. For ‘iOS’: ‘(Void) applicationDidReceiveMemoryWarning:’ ? 4. For ‘Android’: ‘onLowMemory()’ ???
PS: Somewhere I read there’s no need to call this function in cocos2dx 3.x. If this is true: a) Why does this function still exist ? b) Who care about unused texture and unload them ?
You cant simply use Director::purgeCachedData() as the image needed are loaded into textureCache.
I suggest you to load or reload the image on a transition scene between scene if textureCache have been released on low memory or by Director::purgeCachedData().
Memory management is going to be a consideration on practically every project you work on. There are no hard and fast rules as to when to release stored memory. In some circumstances, Cocos’s default functionality of purging the cache after every scene transition will be sufficient, in other cases you will have to manually purge to keep your usage low and not get killed by the OS.
One key consideration is how/when to load and reload textures (most memory usage is textures), and how that will affect your game. If you are doing a texture rich game then you may want to consider preloading some of them behind a “loading” screen, but then be careful about letting the engine automatically purge them and wasting your user’s time.