ios - SwiftUI - 内存泄漏
问题描述
环境
- 卡特琳娜 10.15.7- Xcode 12.0
- 斯威夫特 5.0
简要说明
- 问题 `AppDelegate` 中存在内存泄漏。
- 目标 修复它们,避免不再发生。
- 问题 导致问题的原因可能是什么?我应该在哪里查看或调查时间?
几个月来,我一直在使用 SwiftUI 开发一个应用程序,并创建了我想要的 beta 版本的大部分功能。
现在我可以从仪器工具中看到内存泄漏,下面是屏幕截图。
它指向类的第一行,AppDelegate
并没有告诉我们是什么导致了问题。随着我们使用该应用程序,泄漏检测的数量会增加。
如果您需要,我很乐意提供更多信息。
谢谢你。
代码
AppDelegate.swiftimport 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.
}
}
解决方案
推荐阅读
- shell - 使用 shell 脚本命令从文本中提取 UUID 字符串
- react-native - `useAuthRequest` 总是返回 `dismiss`
- html - 使用 window.print() 时创建封面
- javascript - Document.querySelector 返回 NULL 值 - 脚本位于页面底部
- swift - MapBox 注释标题在 Swift 中居中
- notepad++ - 制作大括号时如何使notepad ++转到下一行
- dpdk - 如何安装 DPDK 内核模块?
- sql-server - 仅当字段在更新之前为 false 时 SQL Server 才会触发
- java - 使用 Lombok 将 JSON 数组映射到 POJO
- javascript - 尝试使用下拉列表文本更改时,更改文本区域中的文本后没有更改?