tags:

views:

112

answers:

2

Hi,

In my application I m using following code below:-

NSArray* toolbarItems = [NSArray arrayWithObjects:
                             [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)], nil];
    [toolbarItems makeObjectsPerformSelector:@selector(release)];

For that it shows Potential leak of an object .

Please help me out.

Thanks in Advance

+4  A: 

Yes that's a potential leak because you created a UIBarButtonItem that you owned (since you invoked alloc), but lost the reference to it by directly putting it into the array. As such, the analyzer is reporting that you leaked it.

Besides that, the code is terrible. I can't think of any valid situation where you'd ever want to do [anArray makeObjectsPerformSelector:@selector(release)];

Dave DeLong
+1  A: 

When you create an array using arrayWith... the object is autorelease so you don't need to release the object. you do release when you create objects with the [[alloc] init] style

Dranes Ragiac