SwiftUI - Memory Leaks

Viewed 319

Environment

- Catalina 10.15.7
- Xcode 12.0
- Swift 5.0

Brief explanation

  • Problem
  • Having memory leaks in the `AppDelegate`.
  • Goal
  • Fix them and avoid not to be occured again.
  • Question
  • What could be the reasons that cause the problems and where should I take a look or investigate time?

I have been working on an app with SwiftUI for a couple of months and have created most of the features that I wanted for the beta version.
Now I have memory leaks that I can see from the instrument tools, and a screenshot is below.

enter image description here

It points to the first line of the class AppDelegate and doesn't tell us what causes the problem. The number of detection of the leaks grows as we use the app.

I am happy to provide more information if you need.
Thank you.


Code

AppDelegate.swift
import UIKit
import FacebookCore
import FBSDKCoreKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions )
        return true
    }
    
    func application( _ app:UIApplication, open url:URL, options: [UIApplication.OpenURLOptionsKey :Any] = [:] ) -> Bool { ApplicationDelegate.shared.application( app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation] )
    }

    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
}
0 Answers
Related