Potential leak of object allocated in iphone

In my application, I use the following code below: -

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

To do this, it shows the potential leak of the object.

+3
source share
2 answers

Yes, a potential leak is due to the fact that you created UIBarButtonItemthat you owned (as you called alloc), but lost the link to it by simply placing it in an array. Thus, the analyzer reports that you have leaked it.

Also, the code is terrible. I can’t think of any real situation when you will ever want to do[anArray makeObjectsPerformSelector:@selector(release)];

+5
source

, arrayWith... autorelease, . [[alloc] init]

+1

Source: https://habr.com/ru/post/1758827/


All Articles