开发者

Potential leak of an object allocated in iphone

开发者 https://www.devze.com 2023-01-11 08:11 出处:网络
In my application I m using following code below:- NSArray* toolbarItems = [NSArray arrayWithObjects: [[UIBarButtonItem alloc] in开发者_运维知识库itWithBarButtonSystemItem:UIBarButtonSystemItemDone t

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

精彩评论

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