The app is a survey in which a user answers a series of questions on different ViewControllers, and the one variable is changed accordingly, presenting a final number at the end of the app.
The code is very basic, and it runs smoothly on the simulator, but crashes when testing on my iPhone due to memory warning.
There are three potential pieces of code using a lot of memory. There are a decent amount of animated images (200 in total) used like so:
cloudAnimation.animationImages = [
UIImage(named: "Home Page Cloud Animation 01.png")!,
UIImage(named: "Home Page Cloud Animation 02.png")!,
UIImage(named: "Home Page Cloud Animation 03.png")! ]
cloudAnimation.animationDuration = 6
cloudAnimation.startAnimating()
Each new ViewController adds about 50-60MBs of data to memory, and I think it may be from the segues. There are 2-3 buttons on each screen. Depending on which they click, the variable is changed. Here is that code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "yesButton" {
var DestViewController : YesViewController = segue.destinationViewController as! YesViewController
DestViewController.percentChance = 0.02
} else if segue.identifier == "noButton" {
var DestViewController : NoViewController = segue.destinationViewController as! NoViewController
DestViewController.percentChance = percentChance
} else if segue.identifier == "goHome" {
var DestViewController : HomeScreenViewController = segue.destinationViewController as!
HomeScreenViewController
}
}
The only other thing that could possibly be messing with the memory is that every view holds the "percentChance" variable, and it is changed and passed from one to another.
Do any of these examples look like they could be using large amounts of memory? How can I deactivate or de-initialize ViewControllers or animations once I am done with them? Any help is greatly appreciated.