1

Usually, my app uses around 50MB of RAM at the most, but I recently noticed that RAM usage was over 100MB.

This happens on a UITableViewController. I have a prototype cell with an UIImageView, and beside it, a UIStackView which contains two labels, and another UIStackView containing a UIImageView and UILabel.

After investigating, I found that it was the UITableViewCell, and more specifically when I have a UIStackView within it. When I load more cells, the memory goes up even higher. I'm not even doing any modification to the cell in cellForRowAt:, and I've tested this with a separate cell just to make sure, and I had the same issue.

Instruments shows that there are no memory leaks.

I'm using Xcode 9 Beta 5 and Swift 4.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)

    return cell
}
dannymout
  • 91
  • 9
  • your `cellForRowAt` code? are you reusing cells? – Bilal Aug 18 '17 at 02:41
  • Just `tableview.dequeueReusableCell` and then returning it. – dannymout Aug 18 '17 at 02:41
  • Are you sure its causing by your stackview but not your image? If your image is huge then maybe thats the reason – Tj3n Aug 18 '17 at 02:50
  • No, it is definitely not. I set the images in `cellForRowAt` and I've gotten rid of everything other than the code for loading the cell. – dannymout Aug 18 '17 at 02:55
  • 1
    @dfd `UIStackView` and `UITableView` are very different. I can see a case for replacing `UITableView` with `UICollectionView` but not with `UIStackView` – Paulw11 Aug 18 '17 at 03:53
  • @dfd: `UIStackView` is at most an alternative for static table views. `UITableView` is very memory efficient, especially for large tables, but this does not apply to `UIStackView`. – clemens Aug 18 '17 at 06:01
  • Which objects does Instruments display as the largest memory consumer? – clemens Aug 18 '17 at 06:03

1 Answers1

0

It seems as if the issue was actually was with the code I was using for dynamic cell heights in the UITableView. So, it has been fixed.

dannymout
  • 91
  • 9