开发者

Potential leak of an object allocated in iphone

In my application I m using following code below:-

NSArray* toolbarItems = [NSArray arrayWithObjects:
                             [[UIBarButtonItem alloc] in开发者_运维知识库itWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)], nil];
    [toolbarItems makeObjectsPerformSelector:@selector(release)];

For that it shows Potential leak of an object .


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)];


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜