is this uibutton autoreleased ?
Posted
by dubbeat
on Stack Overflow
See other posts from Stack Overflow
or by dubbeat
Published on 2010-04-30T09:04:16Z
Indexed on
2010/04/30
9:07 UTC
Read the original article
Hit count: 356
HI This is just a question to check my sanity really. I'm hunting memory leaks that show up in instruments but not the static analyzer.
In one spot the analyzer is pointing to this block of code
UIButton *randomButton = [UIButton buttonWithType:UIButtonTypeRoundedRect ];
randomButton.frame = CGRectMake(205, 145, 90, 22); // size and position of button
[randomButton setTitle:@"Random" forState:UIControlStateNormal];
randomButton.backgroundColor = [UIColor clearColor];
randomButton.adjustsImageWhenHighlighted = YES;
[randomButton addTarget:self action:@selector(getrandom:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:randomButton];
For some reason I thought the above code would auto release the button because I'm not calling init or alloc? If I add [randombutton release] at the bottom of the code my button fails to show. Could somebody describe to me the correct way to release a button from memory that is created in the above way?
Or would I be better off making the button a class variable and sticking the release in the dealloc method?
© Stack Overflow or respective owner