views:

368

answers:

2

I have multiple UIView animations running in my app. They are very short, and then make callbacks to a method that then usually fires off another animation. This leads to a lot of little animations running at the same time, each firing back callbacks.

This actually performs pretty well, and for the first few levels (the app is a game), no problems are observed. However, as you continue to play deeper into the game, I'm starting to get memory warnings and ultimately crashes. I've put NSLog in all of my dealloc methods, so I can see that everything is being properly released and dealloc'd. I've also run static analysis on the app and fixed anything it found.

The weird part to me is this: Shouldn't any performance problems caused by running multiple animations be processor bound (i.e. shouldn't I see a bunch of slowdown and such)? It seems that everything performs just fine, it just runs up memory too fast and there's nothing more I can free. Is there something in the framework on the UIView side of things that will need lots of memory to do these operations? Is there perhaps a leak in the framework I need to avoid when doing these?

Additional note: I'm animating a custom class that extends UIView and has a label and a UIImageView inside of them.

+1  A: 

Multiple animation shouldn't cause memory warnings..

I suggest you should run Instruments for Leaks, ObjectAlloc & CPU Samplers.. That would give a much better view than NSLogs in dealloc

Prakash
Looks like the multiple animations are performing fine. You were right - I had a few things inside of the custom views I'm animating that were incorrectly alloc'd/released and were causing the leak. I was confident my classes were being correctly dealloc'd (and they were) but I missed that I was leaking some core UI classes in the process.
Bdebeez
A: 

You don't show any code so it's hard to give specific advice, however, have you considered using Core Animation layers instead of UIViews? If you need to animate text, you'll have to use a view since there is no CATextLayer on the phone, however, Core Animation provides the facilities to draw complex sprites in a 2d space making it a great candidate for many games.

Best Regards.

Matt Long