I seem to be experiencing a memory leak with compositional layout where my group size is causing my header and cells to experience extremely high memory usage. Just to explain in more detail I'm trying to layout a horizontal grid where items have a 1:1 ratio based on the width of the screen.
In my case I want 5 items per row which are 20% of the screen size with 1px spacing in between each item. And the height of the headers should be estimated so they are self sizing based on their content. So below is a snippet of what I have so far below.
If I change the following code above to this below where I define an absolute value for the section header, everything renders fine and there are no issues.
Any ideas why this might be the case?
In my case I want 5 items per row which are 20% of the screen size with 1px spacing in between each item. And the height of the headers should be estimated so they are self sizing based on their content. So below is a snippet of what I have so far below.
Code Block // MARK: Sizing Constants private let itemRatio: CGFloat = 0.2 var layout: UICollectionViewCompositionalLayout { UICollectionViewCompositionalLayout { [weak self] (sectionIndex, _) -> NSCollectionLayoutSection? in guard let self = self else { return nil } let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(self.itemRatio), heightDimension: .fractionalWidth(self.itemRatio))) item.contentInsets.trailing = 1 item.contentInsets.bottom = 1 let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalWidth(self.itemRatio)), subitems: [item]) let section = NSCollectionLayoutSection(group: group) // Enable this when finish working on the cells section.boundarySupplementaryItems = [ .init(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .estimated(38)), // Investigate why this is causing a memory leak... elementKind: "CollectionViewHeader", alignment: .topLeading) ] return section } }
If I change the following code above to this below where I define an absolute value for the section header, everything renders fine and there are no issues.
Code Block // MARK: Sizing Constants private let itemRatio: CGFloat = 0.2 var layout: UICollectionViewCompositionalLayout { UICollectionViewCompositionalLayout { [weak self] (sectionIndex, _) -> NSCollectionLayoutSection? in guard let self = self else { return nil } let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(self.itemRatio), heightDimension: .fractionalWidth(self.itemRatio))) item.contentInsets.trailing = 1 item.contentInsets.bottom = 1 let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalWidth(self.itemRatio)), subitems: [item]) let section = NSCollectionLayoutSection(group: group) // Enable this when finish working on the cells section.boundarySupplementaryItems = [ .init(layoutSize: .init(widthDimension: .fractionalWidth(1), // heightDimension: .estimated(38)), // Investigate why this is causing a memory leak... heightDimension: .absolute(sectionIndex < 1 ? 120 : 72)), // Investigate why this is causing a memory leak... elementKind: "CollectionViewHeader", alignment: .topLeading) ] return section } }
Any ideas why this might be the case?