ios - 如何解释这个 iOS Instruments 数据?

标签 ios instruments

我创建了一个示例应用程序,它声明了一个宏,如下所示:

#define kSampleString @"didReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarningdidReceiveMemoryWarning"

当用户点击下面的事件处理程序时,我会记录宏字符串。

-(IBAction)SampleMethod:(id)sender{
    NSLog(@"Log %@",kSampleString);
}

下面是我得到的仪器数据:

enter image description here 在检查 Instruments 中的分配时,我得到了以下信息。我能够发现分配发生在 NSLogv 调用中标记为红色的区域中。但是如何解释关于 NSLogv 发生的其他事情。这些 malloc 操作发生了什么?

最佳答案

Malloc 只是 objective-c 的 alloc 的 C 版本,最终会在执行 alloc 时调用。 Instruments 正在跟踪您应用程序中的所有分配,因此 Malloc 出现是很自然的。

至于 CFString,它是 NSString 的 CoreFoundation 堂兄弟(因为 NSString 是围绕 CFString 构建的类集群),无论如何你总是应该向 NSLog() 传递一个不可变的字符串,所以这很有意义.如果您的应用程序正在泄漏内存,那将是一个问题,但目前,一切都很好。

我会担心的是巨大的 1.5 KB 字符串 Malloc 大约位于列表的一半。对于一个简单的字符串来说,这似乎占用了太多内存。

关于ios - 如何解释这个 iOS Instruments 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10527053/

相关文章:

iOS应用程序默认运行在后台模式

xcode - 帮助查找内存泄漏(一般提示)

ios - 字符串格式化程序中的内存泄漏

ios - 出现键盘时向上移动 View

ios - Shoutem 将 Prop 传递到另一个屏幕

ios5 - 无法将iPhone 3gs(iOS 5.0.1)与Instruments应用程序连接

ios - 如果堆分配内存达到5GB,iOS应用程序会拒绝吗

ios - Google Maps 会导致高事件字节数吗?

ios - 找不到 GPPSignIn.h 文件

ios - 集中放置 Collection View 单元格