Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Lee Hardy
Lee Hardy
5,407 Points

iOS Crystal Ball Performance tweaks

Hi all,

Just completed the iOS tutorial, thoroughly enjoyed it and found it very useful. I put the app on my iPhone 4s. It works fine but I noticed that when the image is first animated (i.e. first touch or shake) that it takes a good few seconds for the animation to load.

Looking in XCode I saw that memory usage went from around 12MB to 170MB when it first animates, so it looks like this is the NSArray containing the animation image objects loading for the first time.

My question is, is there anyway this can be optimised in code? i.e. when the application is loading can I move the NSArray initialisation method to elsewhere so that I can load it at startup instead of when it is first called? I believe it is currently in the viewDidLoad method as per the tutorial, which I assumed would load the NSArray into memory

Thanks

Lee

2 Answers

Hi Lee,

I believe if you pull the animation array out (create a custom class) and modify the Crystal Ball files (.h & .m), as indicated by the extra credit for the Refactoring into a Model where we had to pull the prediction array out of the DidLoad method. I think this would optimize your code. At least that's what I would try first.

Happy coding!

Shani

Lee Hardy
Lee Hardy
5,407 Points

Thanks Shani for the recommendation, I will try this and see how it goes