I'm newbie(ish) iOS developer using Alamofire for the first time to make multiple GET requests for an iOS 9.3 app:
var i = 0
while i < 100{
var url = String("https://itunes.apple.com/search?term=" + "somequery")
Alamofire.request(.GET, url).responseJSON {[weak self] response in
switch response.result {
case .Success:
break
case .Failure(let error):
print(error)
}
}
i++
}
Every request made increases the app's memory usage, and then never releases it. I've used Instruments to try to get a better idea of what is happening and it seems like this is an issue related to CFNetwork.
Things I have tried to resolve the issue:
- cancel each task in the session as described here
- use dispatch groups as described here
- clear NSURLCache using NSURLCache.sharedURLCache().removeAllCachedResponses()
- invalidate and cancel the session using session.invalidateAndCancel()
- change the requestCachePolicy to .ReloadIgnoringLocalCacheData
Why does this occur and how can I release the memory after the requests are complete?