Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27133

Memory leaks Xcode 8 instrument

I do nothing on my view controller and I see the graph that is changing while app is working.

Are this really leaks?

enter image description here

First time it show green check mark then it show 1 leak and then no new leaks.

So it means that there are no leaks or there are still 1 leak but not new ones?

I have actually app delegate which contains strong reference of manager.

class AppDelegate {

var applicationManager = ApplicationManager()

}

and I have few services in ApplicationManager

class ApplicationManager
{
  lazy var apiService: APIService = {

    let service = APIService()

    return service

  }()

  lazy var facebookService: FacebookService = {

    let service = FacebookService()

    return service

  }()
}

I have a function

func logInUser()
  {
    guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
      fatalError()
    }

    let apiService = appDelegate.applicationManager.apiService

    guard let email = emailTextField.text, let password = passwordTextField.text else {
      return
    }
    apiService.loginUserWith(email, password: password) {(result) in
}

could this code leads problems?

Using new tools I also see

that I have one leaked object (it's in another previous project) but with the same implementation of manager and services.

enter image description here

Upvotes: 0

Views: 1889

Answers (1)

matt
matt

Reputation: 535139

I'm going to suggest that there is in fact no leak. The Xcode 8.2 release notes say:

The Memory Debugger for macOS and the iOS Simulator fixes reporting of false memory leaks for Swift classes containing either fields of type enum, or classes that inherit from certain Objective-C framework classes. (27932061)

You are using Xcode 8.1, so we know that there is "reporting of false memory leaks for Swift classes" in this version (though under what precise circumstances, and whether the bug is completely fixed even in Xcode 8.2, remains unclear to me).

Moreover, I downloaded your github example project and ran it in Xcode 8.2.1 and saw no leak reported, neither in Instruments nor in the memory graph. Here's the Instruments output:

enter image description here

Upvotes: 2

Related Questions