korgoth Posted May 20, 2014 Share Posted May 20, 2014 What are the best practices for memory management? For example I have a game with a lot of assets ( images,tilemaps,sound ) and a lot of states ( game, menu,level select, world select, etc ).1. how to handle asset loading? a.: load every asset with the preloader state b.: use the preload method on every states and load only the required assets 2. if the "b" method is better, do I need to clear the assets from the Cache when I switch states? For example I load a,b,c image for StateA then load d,e,f image for StateB. The a,b,c images still in the memory when the StateB active. And if I switch to StateC and load g,h,i images the a,b,c,d,e,f images are still in the memory. Or performance not depends on the cached objects?3. do I need to destroy every created object in the shutdown method? for example in the create method: this.sprite = this.add.sprite();this.group = this.add.group(); in the shutdown:this.sprite.destroy();this.group.destroy(); 4. what about local variables? like: var sprite = this.add.sprite(); how to destory them? Do i need to add every local object to a group and destory that? Link to comment Share on other sites More sharing options...
stasuss Posted May 20, 2014 Share Posted May 20, 2014 As for the preloading of the assets, I think, it is about what do you wish to save - network traffic or memory.As for sprites - I think it is better to use the recycling. No need to destroy everything. They aren't using very mush memory. Link to comment Share on other sites More sharing options...
Recommended Posts