libswiftCore.dylib 的 UITableviewController 内存泄漏

UITableviewController memory leak from libswiftCore.dylib

无法找出这个漏洞。 2 小时后我求助于你。

当我转回我的表格视图时,我一直在泄漏。我正在使用自定义表格视图单元格。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ClientTableViewCell
    var client = SharedData.sharedClientList[indexPath.row]
    //cell.fillData(client)

    cell.nameLabel.text = client.clientName

    var tempNeeds = client.needsAsOneStringList()

    var multipleWord = tempNeeds.removeAtIndex(0)

    var others = " | ".join(tempNeeds)
    cell.needLabel.text = "\(multipleWord) \(others)"

    cell.foundAddressLabel.text = "Map Location: \(client.placemark.subThoroughfare) \(client.placemark.thoroughfare) \(client.placemark.locality) \(client.placemark.postalCode)"
    cell.expectedAddressLabel.text = "Searched Location: \(client.importedAddress)"

    cell.hidden = false
    cell.accessoryType = .None

    if !client.isBase {
        if client.clientsBaseAssociation != nil {
            cell.hidden = true
        }
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
        cell.expectedAddressLabel.text = ""
        cell.foundAddressLabel.text = "\(client.placemark.subThoroughfare) \(client.placemark.thoroughfare) \(client.placemark.locality) \(client.placemark.postalCode)"
    }

    return cell
}

我在自定义单元格中确实有一个 fillData 方法,但将其移出,因为我认为我可能是原因 - 但事实并非如此。这是单元格

import UIKit

class ClientTableViewCell: UITableViewCell {

@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var needLabel: UILabel!
@IBOutlet weak var expectedAddressLabel: UILabel!
@IBOutlet weak var foundAddressLabel: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
}

}

iOS 8.4 / Xcode 6.4

接近问题

显然(因为我没有文档来证明这一点)隐藏可重复使用的 table 单元格(.hidden 继承自 UIView)会泄漏内存。也许当隐藏起来时,它被认为不再可重复使用,但也不是一次性的。在任何情况下,解决方案是停止使用特定的单元格隐藏技术来管理 table 视图,而是将未显示的单元格分组到 "logically clipped" 的部分——也就是说,不再显示给dataSourcedelegate 协议方法。 (例如,return 节数减一,或 return "hidden" 节的单元格数为零。)

逻辑裁剪也可以在一个部分中工作,如果愿意做一个reloadSection()然后动态重新计算索引,以便所有"hidden"单元格被排除在外,但其余索引是连续的。根据底层模型的大小,可能必须获得 Computer-Science-y 以避免 O(n^2) 重新索引算法。

Code Review 中遇到了 Objective-C 中的类似问题,但从未得到完整解释:https://codereview.stackexchange.com/questions/42429/uitableview-hidden-section-causing-more-memory-allocations-every-time-on-pull