Message from debugger: Terminated due to memory issue

前端 未结 6 1624
小蘑菇
小蘑菇 2021-02-18 21:52

My app working with Geojson file. I use MapBox SDK to add MGLPolyline to map. But the problem is my file too large, so that the app crash and got the e

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-18 22:48

    First Solution

    Maybe your for loop is running infinitely and allocating memory to an array with nil value every time. It is using high amounts of memory, so it gives this error.

    Please check by print something in the for loop.

    Second Solution

    Add this in didReceiveMemoryWarning:

    NSURLCache.sharedURLCache().removeAllCachedResponses()
    NSURLCache.sharedURLCache().diskCapacity = 0
    NSURLCache.sharedURLCache().memoryCapacity = 0
    

    You can also change the cache policy of the NSURLRequest:

    let day_url = NSURL(string: "http://www.example.com")
    let day_url_request = NSURLRequest(URL: day_url,
        cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData,
        timeoutInterval: 10.0)
    
    let day_webView = UIWebView()
    day_webView.loadRequest(day_url_request)
    

    More information on cache policies here.

提交回复
热议问题