ios - 为什么没有代码的单视图 swift 应用程序会泄漏内存?
问题描述
我创建了一个带有 a 的单视图 swift 应用程序UILabel
。
当我尝试分析此应用程序时,它似乎正在泄漏内存。为什么会这样?
我敢肯定,我在某处缺少步骤或标志,但我无法找到它。
我没有在这个应用程序中编写任何自己的代码。这是一个使用 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 标记),它们通常表示内存使用量的变化并不总是意味着存在内存泄漏,这可能是由许多原因引起的。
正如您所看到的,每个时间戳都会进行检查,因此它会比较这些时间戳之间的内存使用情况并确定是否存在任何潜在的内存泄漏,内存中的这些跳跃并不总是与内存合理的,但更像是发生了变化此时间戳期间的内存,因此您可以检查它,如果它确实是内存泄漏或只是由于某些功能或分配的依赖对象而导致正常内存上升,它是一个监控工具,而不是检测错误工具,即用于监视我们的应用程序内存分配等的变化。
推荐阅读
- c# - WPF 由 Microsoft 或 WPF 社区维护?
- sql - 当我尝试获取制造零件的 MIN 值时,我得到(只有一个表达式......当 EXISTS 没有引入子查询时)
- facebook - 101 Manage_pages 权限已被撤销
- python-3.x - 在 Matplotlib/Seaborn 中将辅助 x 轴与主 x 轴对齐
- python - 如何在可部署的 Electron 应用程序中包含 Python 实例?
- python-3.x - wagtail:Locale_ID 不能为空
- ios - Flutter:找不到“grpcpp/support/byte_buffer.h”文件
- javascript - 我正在尝试创建战舰游戏,但无法找出出现的错误
- java - 如何在响应式 mongo 数据(java)中从 mongoshell 编写查询
- ios - 如何将事件数组保存到 iCalendar