我有这些非常简单的NSViewController和NSTableViewCell子类,当它们组合在一起时会给我带来非常特殊的内存泄漏(由调试内存图和内存泄漏仪器报告)当我在SensorListCellView中包含股票NSPopupButton时。
class ViewController: NSViewController {
@IBOutlet weak var tableSensors: NSTableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
extension ViewController: NSTableViewDataSource, NSTableViewDelegate {
func numberOfRows(in tableView: NSTableView) -> Int {
return 1
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let result:SensorListCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "defaultRow"), owner: self) as! SensorListCellView
// Just fill with any data
result.imageSensorAvailable.image = NSImage(named: NSImage.Name("NSStatusAvailable"))
result.imageSensorAvailable.toolTip = "Sensor is Available & Reporting"
result.sensorID.stringValue = "Sensor ID"
result.sensorDescription.stringValue = "Sensor Description"
result.sensorName.stringValue = "Sensor Name"
// Just fill with any data
result.unitsAvailable.addItem(withTitle: "One")
result.unitsAvailable.addItem(withTitle: "Two")
result.unitsAvailable.addItem(withTitle: "Three")
return result
}
}
class SensorListCellView: NSTableCellView {
@IBOutlet weak var unitLabel: NSTextField!
@IBOutlet weak var imageSensorAvailable: NSImageView!
@IBOutlet weak var sensorID: NSTextField!
@IBOutlet weak var sensorDescription: NSTextField!
@IBOutlet weak var sensorName: NSTextField!
@IBOutlet weak var unitsAvailable: NSPopUpButton!
}
我在Debug Memory Graph中看到了四次泄密。 Here is my very simple storyboard。 所有泄露的CFDictionary对象的描述是:
Printing description of $0:
{
kCUIMeasureEdgeInsetBottomLeft = "NSSize: {9, 3}";
kCUIMeasureEdgeInsetTopRight = "NSSize: {8, 6}";
"measure.height" = 20;
"measure.width" = 24;
}
如果我删除NSPopupButton,内存泄漏就会消失。说我不知所措是轻描淡写。无论我对NSPopupButton做什么,我都会从上面的描述中得到四个泄漏。
非常感谢任何帮助,建议或指示。
答案 0 :(得分:0)
对于Xcode 9.4.1,Swift 4,除了“是AppKit”本身泄漏外,我找不到其他答案。从Xcode 10.0-Beta 2开始,不再注意到上述行为。我认为此事已解决。