I have recently upgraded to Cocos2d 2.0 Before that my game was working properly and frame rate was stably on 60fps. After upgrading to 2.0 and changing some code to the new version I have recognized that playing the game for about 3-4 minutes the frame rate drops down to 50, than to about 40.
I have found some mistakes in my code, like deallocating wrongly some sprites, but this the FPS drop was still there.
I am creating sprites and removing sprites continuously in the scene. After each round in the game I am removing the screen elements and creating them again for the new round. Almost all elements are animated and I am stopping all actions before removing them from the scene.
I have found out that if I removing the scene and starting it again, the FPS rate comes back to normal.
What I am doing wrong? I have tried several possible solutions, but I cannot find the route cause.
Could anybody help here?
Oh, I forgot to mention that the code was working fine on Cocos2d 1.x version. I have never recognized any FPS drop with the same code.
Debug or Release? Device or Simulator? ---> Measure performance only in release builds on device.
From the description it sounds a lot like a memory leak where you either get higher and higher memory usage or more and more nodes not deallocating, which means they might continue to run. Perhaps even draw offscreen.
There's many reasons why one version works fine but not another, and who is to tell that this bug is just a new bug introduced during the transition process. I would start with a simple test: do all nodes of the scene run their dealloc method as you remove them? If not, you have a memory leak, perhaps a retain cycle. A simple change in cocos2d's API from an assign property to a retain property is all it takes to cause something like this.
Then check Instruments to find out exactly where you're leaking memory.