Ios7 game slowing down to a crawl after a couple of minutes

Hello,

I am currently using unit3d free version to play around with unity. I have an example build that I play with however im having some odd stuff occur.

The game begins at 30 fps and stays there for about 2-3 minutes. Then the fps begins to drop slowly, 10 minutes later it is at 7fps. The cpu seems to grow slowly starting at 30fps and 34% cpu to 101% and 7fps.

My first initial thought was that there is a memory leak. After looking in the xcode profiler the memory grows to around 72mbs and hovers there. I also check the number of objects in my scene and it hovers around 1090.

The cpu just grows and grows over time.

I have an iphone 5 ios 7.

here are some screens:
http://d.pr/i/BCEy
http://d.pr/i/l0hW
http://d.pr/i/P560

I am not sure what can be causing this.

Has anyone run into this problem?

Is it possible that you instantiate and delete gameobjects at runtime? How many gameobjects are in your scene at startup (1090 are a lot)? When destroying gameobjects you should use Resourcess.UnloadUnusedAssets() and System.GC.Collect() to free memory and objects. Another problem could be querying the scenegraph in Update() like GameObject.GetComponents(), GameObject.Find() or similar functions that have to iterate the entire scene.

Harry

Hello, thank you for your response.

I am creating game objects in my scene, in on destroy I call the garbage collector and UnloadUnusedAssets however this does not make difference. Yesterday I removed creating these instances and just had a sprite. My game was still slowing down. Im not sure what the problem could be.

Try to build a version without any dynamic objects and check whether the memory consumption still goes up. The CPU load hints to a problem in your script so check for any dynamic array structures and/or scene queries.

Harry

So I stopped instancing objects and the cpu still seems to slowly throttle. Im still not convinced it is a Memory leak since the total number of objects hovers around 1090. The game runs fine for the first 2-3 minutes and then the cpu throttles to 100% (it takes 2 minutes to reach this).

Here is what the console says:
Unloading 0 unused Assets to reduce memory usage. Loaded Objects now: 989.
Total: 6.259125 ms (FindLiveObjects: 0.358208 ms CreateObjectMapping: 0.105500 ms MarkObjects: 5.722875 ms DeleteObjects: 0.027250 ms)

The only think that i can see is the Mark objects do seem to climb with the cpu. At one point it reaches about 30ms

The messages informs you that 0 unused assets have been removed which means that all previously instantiated and even destroyed assets still exists in memory. As an alternative don’t do GC.Collect() and Asset.UnloadUnusedAssets() in OnDestroy, instead try to call these methods every 5 or 10 seconds. Does the problem still exists if you close all apps reboot the device and restart the test?

here is after 12 minutes:
Unloading 0 unused Assets to reduce memory usage. Loaded Objects now: 1027.
Total: 51.475330 ms (FindLiveObjects: 0.561291 ms CreateObjectMapping: 0.107000 ms MarkObjects: 50.687836 ms DeleteObjects: 0.047416 ms)

Mark Objects is taking up 50 ms and keeps going up.

I would say that your dynamic objects aren’#t unloaded. Try to call Asset.UnloadUnusedAssets() outside OnDestroy or use Invoke(“CleanUp”, 1f) with

Which Unity version are you using?

Harry,

First of all thank you for taking time to help me. I am using unity 4.2 (the latest) and 2dtoolkit 2.0.
I initially thought that my version of unity was not compatible with iOS 7. So I upgraded last night with no luck on the problem.

Currently I am not querying the scene in any way. I am just instanciating objects offscreen, letting them scroll across and then they self themself call destroy . These objects are rather large ish some textures are 300x300, however they are diced up.
Do you have any clue what MarkedObjects means?

Thanks

I don’t have any informations about the MarkedObjects but as I mentioned earlier the first line is more important (number of unloaded assets and loaded objects). Did you test your app inside the unity editor and watch the stats window for increasing draw calls and memory consumption?

Draw calls are around 20 and 20 for saved. Memory hovered around 34 mb.

I have tried some of your suggestions and still see slow downs. Thank you there are all great. There is 1 asset that is unloaded at the start but that is about it. What does it look like for you when objects are destroyed. Does it say x many objects destroyed every-time it logs to the console.

If you’re unloading only one asset then UnloadUnusedAssets() won’t solve the problem because it happens anywhere else.Did you search the 2D Toolkit forum for any memory issues?
If you’re interested you can send me your project and I use Unity’s profiler (pro version) to test what part of your scripts slow down the cpu.

Not that this directly resolves your problem but in reading your explanation of what you are doing … you should be using an Object pool and then just recycling the objects once they have moved out of bounds. Using an object pool would also process much faster in game as you are then not assigning new objects all the time which has performance costs