Hi,
I'm building an ios app for iPad (swift 3) and keep getting crashes with the message 'Terminated due to out of memory'. I can't seem to find a pattern on which this is caused and I've tried a lot of posible solutions but can't seem to solve it.
First, some information about my app:
- I have zombies disabled
- I'm testing on an iPad Air, 32Gb with 4.05Gb free.
- The app can just crash without any other warning or message on the console but the 'terminated due to out of memory'
- I'm not using segues at all.
- I have 2 modules on the app, one for each role on my app (parent and child). One module uses navigation controllers and the other one doesn't.
For the one with navigation controller I use push and pop instructions
// To go forward
let storyboard = UIStoryboard(name: "storyboardid", bundle: Bundle.main)
let viewController = storyboard.instantiateViewController(withIdentifier: "viewcontrollerid")
self.navigationController?.pushViewController(newViewController, animated: true)
// To go back
viewController.navigationController?.popViewController(animated: true)
// First
let storyboard = UIStoryboard(name: "storyboardid", bundle: Bundle.main)
let newViewController = storyboard.instantiateViewController(withIdentifier: "viewcontrollerid")
newViewController.transitioningDelegate = self.rightToLeftDelegate
viewController.present(newViewController, animated: true, completion: nil)
// Second
let storyboard = UIStoryboard(name: "storyboardid", bundle: Bundle.main)
let newViewController = storyboard.instantiateViewController(withIdentifier: "viewcontrollerid")
newViewController.transitioningDelegate = self.rightToLeftDelegate
viewController.present(newViewController, animated: true, completion: {
viewController.view.window?.rootViewController = newViewController
})
// Third
let storyboard = UIStoryboard(name: "storyboardid", bundle: Bundle.main)
let newViewController = storyboard.instantiateViewController(withIdentifier: "viewcontrollerid")
newViewController.transitioningDelegate = self.rightToLeftDelegate
let parentViewController = self.getViewControllerToPresentFrom(viewController) // To ensure that only the parent presents view controllers
parentViewController.present(newViewController, animated: true, completion: {
parentViewController.view.window?.rootViewController = newViewController
})
fileprivate func getViewControllerToPresentFrom(_ viewController:UIViewController) -> UIViewController {
if viewController.parent != nil {
return self.getViewControllerToPresentFrom(viewController.parent!)
} else {
return viewController
}
}
To set the root view controller I use the following code on AppDelegate
// I set the root VC dynamicaly because it depends on wether it's the first time to use the app or if the user is logged in or not
let storyboard = UIStoryboard(name: "storyboardid", bundle: Bundle.main)
let viewController = storyboard.instantiateViewController(withIdentifier: "viewcontrollerid")
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
if let window = self.window {
inWindow.rootViewController = newViewController
}
- I've been using the Leaks Instrument to try to find out what is going on but can't seem to find anything or maybe I don't understand it quite well.
- This are screenshots of the stack trace of 3 leaks found: http://imgur.com/a/tDYva
- One is when I just open the app and do nothing, the other one is just while navigating and the third is the last one cought by the instrument before it crashed because of the 'out of memory' issue.
- I have the leak file if any one is intrested
- On Xcode's debug navigator, energy impact goes from zero to high and memory gets sometimes up to 450 MB (and won't go down)
- Some view controllers get info from a web api
let session = URLSession.shared
let endpoint = URL(string:"http stuff")!
let request = NSMutableURLRequest(url: endpoint)
request.httpMethod = "GET"
request.setValue(("application/json; charset=utf-8"), forHTTPHeaderField: "Content-Type")
request.setValue("Basic \(TAAuthConfiguration.getToken()!)", forHTTPHeaderField: "Authorization")
session.dataTask(with: request as URLRequest, completionHandler: {(data:Data?, response: URLResponse?, error: Error?) in
// Stuff
}).resume()
The only kind of pattern I see is that it crashes when I'm going from one view to another. Sometimes it crashed at the tenth view presented, sometimes I ned quite a long time to get it to crash.
Somewhere I read that there was some kind of bug on the navigation controller on ios 10, could it be?
I hope there is someone on this forum that could give me a hint as to what could be happening. I'm really lost and could use a helping hand on the matter.
Oh and, sorry for the bad english :s I'm not english native speaker.
Thank you