I am building an application in Xcode 6.2, for iOS 8.1. I have a UIViewController
(LevelViewController
) which contains a UICollectionView
whose cells each represent a level in my game (each one has a label w/ a number). Once one of the cells is selected I perform a show segue to an SKScene
which loads all the data for that particular level.I also have a "menu" button which performs a show segue back to the main menu.
Functionally this all works, however I am having serious memory problems after performing both segues. After peeking in instruments it appears that when I segue out of the LevelViewController
that all of the UILabel
that I added for each individual UICollectionViewCell
remain in memory, along with everything else contained in the cells. There should only be 192 labels (for 192 levels) but after performing this segue several times they add up to around 1000 in instruments.
Obviously these are not being deallocated in memory, It's my understanding that swift should take care of that, so i'm not sure what the problem is. I should also note that the UICollectionView
was added programmatically, and no IBOutlets
are used.
So how exactly can I get rid of those labels, and really, the UICollectionView
itself when I segue away from the LevelViewController
. Im seriously confused about this and it's ruining my St. Patricks Day. So for the love of all things Irish please help a lad out :)
Note: methods I have tried
self.collectionView.removeFromSuperView()
self.collectionView = nil
self.collectionView.deleteItemsAtIndexPaths(path)