Hi all ……
You know iPhone doesnot have garbage collection like ANDROID. So it becomes the responsibility of the developer or programmer to release the resources and remove the unwanted textures from your memory.
If you don’t remove the unused textures and other variables from your memory your application will exit after a while.
You often have the problem that your iPhone application exits unexpectedly, Most probably this may be the reason.
One method to check is…….
1. Release variables declared inside a function from there itself.
2. Release other variables inside the dealloc() function.
3. Remove the textures that remain in memory when you use images.
4. If you are using particle effects then don’t use the particle release function.
5. Unload the sounds on dealloc.
For removing the variables you can use..
For removing the textures from the memory use this code inside the dellaoc function.
Check out the console if it is working. It will show console outputs such as “removing unused texture bla bla bla..”
/** this will remove all the unused frames if you are using sprite sheets **/ [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
/** this will remove unused textures of images if you are using only images **/ [[CCTextureCache sharedTextureCache] removeUnusedTextures];
/** this will remove all textures from memory **/ [[CCTextureCache sharedTextureCache] removeAllTextures];
But still your program may exit. This is due to the second line and put only the this line..
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
This may solve your problem…….
This above code will release most of your unused memory.
Please leave your valuable comments if this post was useful…..