Swift由于内存问题而终止

时间:2017-07-02 10:20:55

标签: ios swift

我注意到在我的应用程序中重新加载MapKit View后,应用程序崩溃,我收到错误Message from debugger: Terminated due to memory issue我认为这是因为我在viewDidLoad()初始化了很多变量,例如:

    // LOCATIONS
    let windcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.055961,174.072288)
    let bcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.057487, 174.054154)
    let hatcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.069150, 174.081657)
    let halocoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.058951, 174.073410)
    let rockcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.010627, 174.178184)
    let pixelcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.057265, 174.073791)
    let signcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.058316, 174.051954)
    let wheelcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.056593, 174.072684)
    let tukocoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.056812, 174.072730)
    let faeocoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.059038, 174.070527)
    let cloudcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.059515,174.073706)
    let snakecoord:CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.057154, 174.072670)
    let shinycoord:CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.05602950741741, 174.0699454416841)
    let doncoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.009391, 174.178753)
    let anchorcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.055985, 174.072476)
    let catcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.066965, 174.079661)
    let colour_polecoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.057508,174.072513)
    let collection_coord:CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.058208,174.070732)

与许多其他人一起。我想,但是当应用程序首次加载相应的视图时viewDidLoad()只运行一次?我可以将这些声明放在一个单独的类中并创建该类的对象并保持对它的引用吗?或者有更简单的方法来做到这一点。下图显示了内存使用情况(峰值来自返回MapKit View。)

Memory Usage of app

1 个答案:

答案 0 :(得分:0)

使用Unwind Segue Used this for reference.

修复了问题