     }
     
     //MARK: Private Properties
-    private var delegate: CollectionViewWaterfallLayoutDelegate  {
+    private weak var delegate: CollectionViewWaterfallLayoutDelegate?  {
         get {
-            return collectionView.delegate as CollectionViewWaterfallLayoutDelegate
+            return collectionView.delegate as? CollectionViewWaterfallLayoutDelegate
         }
     }
     private var columnHeights = [Float]()

            }
            
            var footerInset: UIEdgeInsets
            if let inset = delegate.collectionView?(collectionView, layout: self, insetForFooterInSection: section) {
                footerInset = inset
            }
            else {

            * 1. Get section-specific metrics (minimumInteritemSpacing, sectionInset)
            */
            var minimumInteritemSpacing: Float
            if let height = delegate?.collectionView?(collectionView, layout: self, minimumInteritemSpacingForSection: section) {
                minimumInteritemSpacing = height
            }
            else {
