Alamofire GET Request a memory leak (Swift)

I am an iOS (ish) iOS developer using Alamofire for the first time to make multiple GET requests for an iOS 9.3 application:

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++ } 

Each request made increases application memory usage and then never releases it. I used tools to try to better understand what is happening, and it looks like this is a CFNetwork related issue.

Tools Screenshot + Memory Leak

What I was trying to solve the problem:

  • cancel each task in the session as described here
  • use sending groups as described here
  • flush NSURLCache using NSURLCache.sharedURLCache (). removeAllCachedResponses ()
  • cancel and cancel the session using session.invalidateAndCancel ()
  • change requestCachePolicy to .ReloadIgnoringLocalCacheData li>

Why is this happening and how can I free up memory after completing requests?

+6
source share

All Articles