SwiftUI-内存泄漏

时间:2020-10-03 03:22:34

标签: ios swift xcode memory-leaks swiftui

环境

-卡塔琳娜10.15.7
-Xcode 12.0
-Swift 5.0

简要说明

  • 问题
  • AppDelegate中的内存泄漏。
  • 目标
  • 修复它们,避免再次发生。
  • 问题
  • 造成问题的原因可能是什么?我应该去哪里看看或调查时间?

我已经使用SwiftUI开发了一个应用程序几个月,并创建了测试版所需的大多数功能。
现在我可以从仪器工具看到内存泄漏,下面是屏幕截图。

enter image description here

它指向类AppDelegate的第一行,并且没有告诉我们是什么引起了问题。 随着我们使用该应用程序,检测到泄漏的数量也在增加。

如果您需要,我很乐意提供更多信息。
谢谢。


代码

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 个答案:

没有答案