2015-08-08 31 views
0

找不到這個泄漏。 2個小時後,我訴諸你的幫助。來自libswiftCore.dylib的UITableviewController內存泄漏

當我回到我的tableview時,我一直在泄漏。我正在使用自定義的tableview單元格。

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/6.4的Xcode

enter image description here

enter image description here

更接近問題

enter image description here

+0

通過排除法,是不是一定要在'client.needsAsOneStringList()'?其他所有東西都在堆棧中或連接到可重用的單元屬性。外界可能沒有足夠的背景來解決這個問題。用ARC,一定不能是一個強大的參考週期? – BaseZen

+0

會嘗試..並更新你 – DogCoffee

+0

是否有那些「棘手」的計算屬性? – BaseZen

回答

0

顯然,(因爲我不HAV e文檔證明它)隱藏可重複使用的表格單元格(.hidden繼承自UIView)泄漏內存。也許在隱藏時,它被認爲不再可用,但也是非一次性的。在任何情況下,解決方案都是停止使用特定的單元隱藏技術來管理表格視圖,而是將未顯示的單元格分組爲「邏輯剪輯」的部分 - 也就是說,不再透露給dataSourcedelegate協議方法。 (例如,返回一個少區段計數,或返回零細胞計數爲「隱藏」的部分。)

邏輯剪裁也內工作如果一個人願意做一個部分一個reloadSection(),然後動態地重新計算這些索引使得所有「隱藏的」單元格都被省略,但其餘索引是連續的。根據基礎模型的大小,可能需要使用Computer-Science-y來避免O(n^2)重新索引算法。

在Objective-C類似的問題在代碼審查遇到過,但從未充分地解釋:https://codereview.stackexchange.com/questions/42429/uitableview-hidden-section-causing-more-memory-allocations-every-time-on-pull