Ios 如何解决连续阵列存储<;UIButton>;Swift内存泄漏?

Ios 如何解决连续阵列存储<;UIButton>;Swift内存泄漏?,ios,swift,memory-leaks,uibutton,Ios,Swift,Memory Leaks,Uibutton,我是新的泄漏仪器,并开始学习如何修复内存泄漏。我有以下代码: class InputButtonsContainerView: UIView { var hexButtons = [UIButton]() required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) //Configure buttons for view in subviews { for btn in

我是新的泄漏仪器,并开始学习如何修复内存泄漏。我有以下代码:

class InputButtonsContainerView: UIView {

var hexButtons = [UIButton]()

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    //Configure buttons
    for view in subviews {
        for btn in view.subviews where btn is UIButton {
            let button = btn as! UIButton
            button.layer.borderWidth = 1
            button.layer.borderColor = UIColor.black.cgColor
            button.layer.cornerRadius = SizeAdaptation.shared.inputButtonCornerRadius
            button.titleLabel?.font = UIFont.systemFont(ofSize: SizeAdaptation.shared.inputButtonFontSize)
            if button.tag > 9 && button.tag < 16 {
                hexButtons.append(button)
            }
        }
    }
    defer{
        inputMode = .dec
    }
}

var inputMode = MakerInputMode.dec {
    didSet{
        switch inputMode {
        case .dec:
            for btn in hexButtons {
                btn.layer.borderColor = UIColor.lightGray.cgColor
                btn.setTitleColor(UIColor.lightGray, for: .normal)
            }
        case .hex:
            for btn in hexButtons {
                btn.layer.borderColor = UIColor.black.cgColor
                btn.setTitleColor(UIColor.black, for: .normal)
            }
        }
    }
}
}
泄漏仪表显示init功能中存在泄漏: 似乎
ui按钮
数组被释放了两次,导致引用计数为-1。有人知道如何解决这个问题吗?多谢各位

class AddColorViewController: UIViewController {
    @IBOutlet weak var inputButtonsContainerView: InputButtonsContainerView!
    ....
}