Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内存每15秒增加一次,怀疑JSON/字符串问题。_Json_Xcode_Swift_Nstimer_Alamofire - Fatal编程技术网

内存每15秒增加一次,怀疑JSON/字符串问题。

内存每15秒增加一次,怀疑JSON/字符串问题。,json,xcode,swift,nstimer,alamofire,Json,Xcode,Swift,Nstimer,Alamofire,我正在制作的应用程序几乎完成了,但是我看到每15秒内存就会增加一次,直到应用程序崩溃。它增加约10mb/15秒 这个应用程序非常简单 我在ApplicationIDFinishLaunching中调用一个重复计时器,如下所示: timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "refreshIpAddresses", userInfo: nil, repeats: true) 计时器调用

我正在制作的应用程序几乎完成了,但是我看到每15秒内存就会增加一次,直到应用程序崩溃。它增加约10mb/15秒

这个应用程序非常简单

我在
ApplicationIDFinishLaunching
中调用一个重复计时器,如下所示:

    timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "refreshIpAddresses", userInfo: nil, repeats: true)
计时器调用一个名为
refreshIpAddresses()
的函数,该函数将调用另外3个函数。这是如下所示:

func refreshIpAddresses() {
    getPrivateIp()
    getIpData()
    getDnsData()
}
每一个都是相似的,所以我只演示其中一个。下面的代码是方法
getDnsData()

如果我注释掉计时器,内存增加就不再是问题了

我的计时器是否以某种方式在每个循环中存储信息?它应该在什么地方失效吗?这是我的
getDnsData()
方法吗

请帮忙

编辑可能不是由于NSTimer。有人能指导我如何找出问题所在吗

以下是仪器中的内存泄漏检查:

JSON()的作用是什么?它来自SwiftyJSON的库。它从JSON数组获取数据。请参阅此处的用法部分,我认为问题不在于此代码示例。可能是别的原因。我还将关注分配的跳跃,而不是“泄漏”图表。分配的跳跃很大,因此我会选择一个较短的范围(通过在该点之前和之后拖动一个时间范围),然后查看该时间段内的分配情况。然后,您可以确定这些分配是什么,并返回这些分配的位置(假设您在Instruments中保持“record reference counts”(记录参考计数)功能打开)。嗯,好的。如果你有时间,这是仪器
func getDnsData() {
    Alamofire.request(.GET, dataSourceURL2!)
        .responseJSON { response in

            if (response.result.value != nil) {
            let json2 = JSON(response.result.value!)
            let json3 = json2["dns"]
            let geo = json3["geo"].stringValue
            let ip = json3["ip"].stringValue

            self.dnsIp.title = "DNS IP: " + ip
            self.dnsName.title = "DNS Name: " + geo
            } else {
                self.dnsIp.title = "No Internet Connection"
                self.dnsName.title = "No Internet Connection"
            }
    }
}