设置:
我有一个ViewController ProblemView
和class A
。我通过ProblemView
了课堂A
,所以我可以继续努力。它看起来像这样(简化):
class ProblemView: UIViewController{
var instanceOfA = A()
instanceOfA.passView(passedVC: self)
}
class A{
var workOn = ProblemView()
func passView(passedVC: ProblemView){
workOn = passedVC
// I noticed, if I declare a varible locally like var workOn2 = passedVC, my problem is solved -
// but I need the variable globally, because I don't want to pass it around within this class
}
func doSth(){
// here I interact with variables of the passed ViewController
}
}
问题:每当我在应用程序中重新启动此进程时,内存每次都会增加,直到出现内存错误。
我尝试了什么:我添加deinit
到两个课程中。class A
总是被取消初始化但class ProblemView
不是(这可能是问题吗?)。我还发现,当我不在workOn
全局范围内而是在passView
函数内声明时,它工作得很好。但是我需要全局变量,因为我在A
. 什么可能是这个问题的解决方案或解决方法?