gpt4 book ai didi

swift - NSTableCellView View 中的 NSPopupButton 导致泄漏

转载 作者:行者123 更新时间:2023-11-28 07:46:22 28 4
gpt4 key购买 nike

环境

  • Xcode:9.4.1
  • swift :4
  • 目标平台:10.11

问题

我有这些简单得可笑的 NSViewController 和 NSTableViewCell 子类,它们结合起来会给我带来非常奇怪的内存泄漏(如 Debug Memory GraphMemory Leak Instrument 所报告)当我在 SensorListCellView 中包含一个库存 NSPopupButton 时。

代码 stub

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 做什么,我都会根据上面的描述得到四个漏洞。

如有任何帮助、建议或指导,我们将不胜感激。

最佳答案

对于 Xcode 9.4.1、Swift 4,除了“是 AppKit”本身在泄漏,我找不到其他答案。从 Xcode 10.0 - Beta 2 开始,不再观察到上述行为。我认为问题已解决。

关于swift - NSTableCellView View 中的 NSPopupButton 导致泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50883170/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com