仪器无法检测UIButton泄漏?

发布于 2024-09-28 04:10:59 字数 528 浏览 2 评论 0原文

我是该仪器的新手,我想测试它如何检测内存泄漏。所以我使用下面的代码。当用户单击按钮时它会被触发。

-(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲念泪 2024-10-05 04:10:59

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文