开发者

instrument can't detect UIButton leak?

开发者 https://www.devze.com 2023-01-20 00:16 出处:网络
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.

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 a开发者_JAVA百科ppendString:@"\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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号