为什么没有代码泄漏内存的单视图快速应用程序?

时间:2019-07-01 05:08:58

标签: ios swift memory-leaks profiling

我创建了一个带有UILabel的单视图swift应用程序。

当我尝试分析此应用程序时,似乎正在泄漏内存。为什么会这样?

Screenshot with leaked memory

我确定,我在某处缺少台阶或标志,但是找不到。

我没有在此应用程序中编写任何自己的代码。这是一个使用XCode iOS Single View App模板创建的应用程序。有人可以帮我了解这里发生了什么吗?

编辑1:

代码如下:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
}

class ViewController: UIViewController {
}

还附上了主故事板的屏幕截图。 Screenshot of Main storyboard

1 个答案:

答案 0 :(得分:0)

  

如果您的应用程序中没有代码,则从逻辑上讲不应   任何内存泄漏。

清除后,让我们讨论一下仪器(绿色的复选标记和红色的x标记),它们通常表示内存使用情况的变化并不总是意味着内存泄漏,这原因可能很多。

如您所见,检查是在每个时间戳上完成的,因此它会比较这些时间戳之间的内存使用情况,并确定是否存在潜在的内存泄漏,内存中的那些跳转并不总是以内存为理由,而是更像是在此时间戳记期间发生内存更改,因此您可以检查出它是否确实是内存泄漏,或者由于分配了某些功能或依赖对象而只是正常的内存增加,它是一个监视工具,而不仅仅是检测错误的工具,用于监视我们的应用程序内存分配等的变化。