Is there any memory leak in following code? [closed]
-
07-07-2021 - |
Domanda
I have uibutton as property and releasing it in dealloc. I am just using it to hide or unhide but the frequency of its usage is quite high.
@property (retain, nonatomic) IBOutlet UIButton *object;
-(void)onsomebuttonclick
{
object.hidden=true;
}
- (void)dealloc {
[object release];
}
- (void)viewDidUnload
{
[self setObject:nil];
}
Soluzione
Why not just run
(a) the static analyser
(b) Instruments with the leak tool enabled
or
(c) use ARC?
Altri suggerimenti
That should work fine. As a note, you should set self.object = nil; instead of releasing it to prevent accidental use of the released object.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow