gpt4 book ai didi

ios - 内存使用量随着每个 segue 到模态 vc 的增加而增加

转载 作者:行者123 更新时间:2023-11-28 06:48:17 26 4
gpt4 key购买 nike

我有两个 View Controller ,一个是时间线,第二个是用于创建。在第二个 View Controller 中,我有一个 subview 。这个 subview 是一个 SKView。现在每次我使用它时,它都会增加 2mb 的内存使用量(在真实设备上),但是当我展开它时内存使用量保持不变。
所以它是这样的:我开始使用 12mb,然后它变成 14-15mb。展开后,它保持在 14-15mb 左右。在第二次 segue 之后,它变成 17mb...等等。

这是时间轴 Controller 中使用的代码:

@IBAction func createButtonAct(sender: AnyObject) {

self.performSegueWithIdentifier("create", sender: self)


}

@IBAction func unwindFromCreation(segue: UIStoryboardSegue) {


}




// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == "create"{
let vc = segue.destinationViewController as! CreateViewController
if vc.currCountry == nil || vc.currCountry != self.currCountry{
vc.currCountry = self.currCountry
}

}


}

这是创建 View Controller 的代码:

class CreateViewController: UIViewController, UITextViewDelegate {

@IBOutlet weak var bubbleView: SKView!

@IBOutlet var arrow: UIButton!

var ref: Firebase!


let categories = CatsAndColors.categories


@IBOutlet var doneButton: UIButton!

@IBOutlet var titleField: UITextField!

@IBOutlet var descriptionView: KMPlaceholderTextView!

var choosedCat: String!

var selectedCats: NSMutableArray!

var currCountry:String!

var tap: UITapGestureRecognizer!

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)

UIApplication.sharedApplication().statusBarStyle = .Default
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.arrow.transform = CGAffineTransformMakeRotation(3.14159)
})



titleField.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingChanged)

titleField.addTarget(self, action: "textFieldDidBegin:", forControlEvents: UIControlEvents.EditingDidBegin)

titleField.addTarget(self, action: "textFieldDidEnd:", forControlEvents: UIControlEvents.EditingDidEnd)
// the targets get removed in viewWillDisappear
selectedCats = NSMutableArray()

}



override func viewDidLoad() {
super.viewDidLoad()

ref = Firebase(url: "https://blabber2.firebaseio.com")

self.doneButton.enabled = false

doneButton.setBackgroundImage(UIImage(named: "Done button inactive"), forState: .Disabled)

doneButton.setTitleColor(UIColor(netHex: 0xF6F6F6), forState: .Disabled)

doneButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)

self.setupBubbles()

self.descriptionView.delegate = self

}

func setupBubbles(){



let floatingCollectionScene = ChooseBubblesScene(size: bubbleView.bounds.size)

// floatingCollectionScene.scaleMode = .AspectFit


/*let statusBarHeight = CGRectGetHeight(UIApplication.sharedApplication().statusBarFrame)
let titleLabelHeight = CGRectGetHeight(self.tibleLabel.frame)*/

bubbleView.presentScene(floatingCollectionScene)



for (category, color) in categories {

let node = ChooseBubbleNode.instantiate()
node!.vc = self
node!.fillColor = SKColor(netHex: color)
node!.strokeColor = SKColor(netHex: color)
node!.labelNode.text = category

floatingCollectionScene.addChild(node!)

}


}
...

catsAndColors 结构如下所示:

struct CatsAndColors{

static var categories = ["Crime":0x5F5068, "Travel":0xFBCB43, "Religion":0xE55555, "Tech":0xAF3151, "Economy":0x955BA5, "Games":0xE76851, "Climate":0x6ED79A, "Books":0xE54242, "History":0x287572, "Clothes":0x515151, "Sports":0x4AB3A7, "Food":0xD87171, "Politics":0x5FA6D6, "Music":0xDD2E63, "Tv-shows":0x77A7FB]

}

最佳答案

也许您已经在 View Controller 之间创建了某种保留循环。
如果两个 View Controller 都持有对彼此的引用,则尝试将其中一个引用声明为 weak

有关该主题的更多信息,请阅读 Resolving Strong Reference Cycles Between Class Instances .

关于ios - 内存使用量随着每个 segue 到模态 vc 的增加而增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35632440/

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