The app I am making is almost complete, however I am seeing a memory increase every 15 seconds until the app crashes. It increases ~10mb/15seconds.
The app is pretty simple.
I call a repeating timer in applicationDidFinishLaunching
as shown here:
timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "refreshIpAddresses", userInfo: nil, repeats: true)
the timer calls a function called refreshIpAddresses()
which calls 3 more functions. This is show below:
func refreshIpAddresses() {
getPrivateIp()
getIpData()
getDnsData()
}
Each of these are similar, so I will just demo one of them. The code below is the method getDnsData()
.
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"
}
}
}
If I comment out the timers, the memory increase stops being an issue.
Is my timer somehow storing information every loop? Should it be invalidated somewhere? Is it my getDnsData()
method?
Please help.
EDIT It might not be due to the NSTimer. Can someone guide me how to figure out what the issue is?