Note that there are some explanatory texts on larger screens.

plurals
  1. POProtocol Memory
    primarykey
    data
    text
    <p>I'm sorry for repost. What have really bug me is if property retain should release when:<br> case 1 : (code below) button is already alloc in init: then add to subview then release it, and by any chance I set the button property in another class (I didn't release in dealloc:) it will leak then?<br> case 2 : button is already alloc in init: then add to subview then release it, and by any chance I didn't set the any button property in another class (I didn't use the property) (I release it in dealloc) then it will crash.</p> <p>So what should I do if I want to alloc button in init: and I want to set the property too ?</p> <pre><code>@interface SomeClass : UIView { UIButton *_button; } @property (nonatomic, retain)UIButton *button; @implementation SomeClass @synthesize button = _button; - (id)init { _button = [[UIbutton alloc] initWithFrame:CGRectMake(0.0f,0.0f,100.0f,20.0f)]; [[_button titleLabel] setFont:BUTTON_FONT]; [_button setBackgroundImage:[[UIImage imageNamed:@"button_blue.png"] stretchableImageWithLeftCapWidth:20.0f topCapHeight:15.0f] forState:UIControlStateNormal]; [_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal]; [[_button titleLabel] setShadowOffset:CGSizeMake(0.0f, 1.0f)]; [_button addTarget:self action:@selector(buttonDidTapped:) forControlEvents:UIControlEventTouchUpInside]; [self addSubView:_button]; [_button release]; } - (void)dealloc { //[self.button release]; // case 1 [self.button release]; // case 2 [super dealloc]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload