为什么故事板中的iboutlet会保留内存?

时间:2015-03-16 04:44:04

标签: ios swift storyboard instruments iboutlet

我正在使用swift。有一些自定义的UIControlsUIViews。他们被拖入带有IBOutlet财产的weak故事板。

我在Allocations Instrument中运行了App,并使用所有这些视图和控件呈现了viewcontroller。解散控制器,但已分配的对象在内存中是持久的。在每次呈现控制器的尝试中,内存都相应增长,似乎没有一个被释放。

我在这里添加一个相关的控件

import UIKit

@IBDesignable class CNButtonBackground: UIView {

private func initialize()
{
    //color is set through context fill in drawRect
    self.backgroundColor = UIColor.lightTextColor()
}

override init(frame: CGRect) {
    super.init(frame: frame)

    //initializing custom components
    self.initialize()
}

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

    //initializing custom components
    self.initialize()
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect)
{
    super.drawRect(rect)

    // Drawing code
    self.layer.cornerRadius = 5.0
    self.clipsToBounds = Yes

    // Fill color
    let context = UIGraphicsGetCurrentContext()
    var drawRect: CGRect = CGRectMake(rect.origin.x, rect.origin.y,rect.size.width, rect.size.height);

    CGContextSetRGBFillColor(context, 35.0/255.0, 24.0/255.0, 21.0/255.0, 0.8);
    CGContextFillRect(context, drawRect);
}
}

我错过了什么导致了这个问题?请帮帮我... 我能尝试的任何东西都没问题。给我指示,我愿意尝试所有。

0 个答案:

没有答案