簡體   English   中英

為什么沒有代碼泄漏內存的單視圖快速應用程序?

[英]Why does a single view swift application with no code leak memory?

我創建了一個帶有UILabel的單視圖swift應用程序。

當我嘗試分析此應用程序時,似乎正在泄漏內存。 為什么會這樣?

屏幕截圖顯示內存泄漏

我敢肯定,我在某處缺少台階或標志,但找不到。

我沒有在此應用程序中編寫任何自己的代碼。 這是一個使用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 {
}

還要附上主故事板的屏幕截圖。 主故事板的屏幕截圖

如果您的應用程序中沒有代碼,那么從邏輯上講應該不會有任何內存泄漏。

清除這些內容后,我們可以討論一下儀器(綠色的復選標記和紅色的x標記) ,它們通常表示內存使用情況的變化並不總是意味着內存泄漏,這可能是由多種原因引起的。

如您所見,檢查是在每個時間戳上完成的,因此它會比較這些時間戳之間的內存使用情況,並確定是否存在潛在的內存泄漏,內存中的那些跳轉並不總是以內存為理由,而是更像是在內存中進行了更改該時間戳記中的內存,因此您可以檢查出它是否確實是內存泄漏,或者由於分配了某些功能或依賴對象而只是正常內存增加,它是一個監視工具,而不是檢測錯誤的工具,也就是說用於監視我們應用程序內存分配的變化等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM