仪器无法检测UIButton泄漏?
我是该仪器的新手,我想测试它如何检测内存泄漏。所以我使用下面的代码。当用户单击按钮时它会被触发。
-(IBAction)leak{
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; NSLog(@"%@", 按钮); 按钮.selected = YES; 但仪器
中没有任何反应。怎么会?
我将代码更改为:
-(IBAction)leak{
NSMutableString *test = [[NSMutableString alloc] init]; [测试appendString:@"测试1"]; [测试appendString:@"\n测试2"]; NSLog(@"%@", 测试); 。
仪器告诉我该代码内存在内存泄漏
那么为什么它无法检测到 UIButton 泄漏呢?任何评论将不胜感激!
I'm new to the Instrument, i want to test how it detect the memory leak. So i use the following code. It gets fired when user click on a button.
-(IBAction)leak{
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
NSLog(@"%@", button);
button.selected = YES;
}
but nothing happens in the Instrument. How come?
I changed the code to:
-(IBAction)leak{
NSMutableString *test = [[NSMutableString alloc] init];
[test appendString:@"Testing 1"];
[test appendString:@"\nTesting 2"];
NSLog(@"%@", test);
}
And the Instrument tells me that there's a memory leak inside that code.
So why it can't detect the UIButton leak? Any comment will be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Instruments 不会告诉您您的代码没有泄漏。当 Instruments 检测到泄漏时,肯定存在泄漏。但是,如果它没有检测到泄漏,并不一定意味着您的代码没有泄漏。不要问我为什么,但是存在仪器无法检测到的内存泄漏。
不幸的是,我没有可以引用的官方消息来源。您可能想观看今年的 WWCD 视频,尤其是“使用仪器进行高级内存分析” 。它很好地概述了 Instruments 的功能及其局限性(包括我刚刚告诉您的内容)。
Instruments does not tell you, that your code is not leaking. When Instruments detects a leak, there is definitely one. However, if it doesn't detect a leak, it doesn't necessarily mean that your code is not leaking. Don't ask my why, but there are memory leaks that can not be detected by instruments.
Unfortunately, I have no official source to quote. You might want to watch this years WWCD Videos, especially "Advanced Memory Analysis With Instruments". It give's a nice overview about what Instruments is capable of and about it's limits (including what I just told you).