views:

17

answers:

1

Hi,

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!

A: 

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

Phlibbo
thx 4 ur link! really juicy!
JohnnySun
You're welcome. If this is the answer you needed, please accept it. Thanks!
Phlibbo