I am subclassing UIViewController to prevent code repetition of my ‘masterButtons’ and sets of ‘subButtons’.
It all appeared to be working beautifully until I realised that after about 1200 page changes – navigating between just 3 blank pages (just the buttons and a few other objects showing) the app will always crash!
Instruments (+ testing on a device) does not show any memory leaks, but does show hundreds of instances of these button objects existing! (‘Created & Still Living’ filter selected.)
Also, viewDidUnload / didReceiveMemoryWarning are never called, from any of the ViewControllers!
I have not had these problems on other pages in my app (where UIViewController is NOT subclassed).
So it appears the ViewController’s contents are being re-created, and any previously created are not being deleted.
Are there any common pitfalls of subclassing UIViewController that might be causing this? Is there something I could be missing?
Advice would be greatly appreciated. (I feel like throwing my mac out of the window with this problem!)
Top_ViewController (contains 'MasterButtons')
v
Area1_ViewController (subclass of TOP_ViewController) (contains 'subButtons', and a few texts fields etc.)
v
aPage_ViewController (subclass of Area1_ViewController) (currently blank page)
(Using ARC and storyboards. The storyboard View Controllers have a respective ‘aPage_ViewController’ as their class.)
If you created your storyboard in a loop fashion it might happen that you create new
viewControllersall the time. Each segue transition is creating newviewControllerthus there might be no memory leak but your memory will be consumed.You should be using either
UITabBarControllerorUINavigationControllerto move back and forth and never create loops.Moreover
viewDidUnloadis deprecated in iOS6, perhaps you ignored warning?EDIT:
Try something like this: