Hello,
I am a bit confused about when to use release or autorelease. If I create an UIButton object like this
it will be autoreleased. But, if I add the button to a subview would it be better to alloc the object and then right after adding it to the subview, release it?
Like this:
The autorelease will happend some where in time... but using the release assures the memory to be freed at that very moment?
Any ideas?
MACloop
I am a bit confused about when to use release or autorelease. If I create an UIButton object like this
Code:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor blackColor];
button.frame= CGRectMake(160, 385, 130, 25);
button.titleLabel.font = [UIFont boldSystemFontOfSize: 12];
[button setTitle:@"title" forState:UIControlStateNormal];
[button addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside];
[myScrollView addSubview:button];
it will be autoreleased. But, if I add the button to a subview would it be better to alloc the object and then right after adding it to the subview, release it?
Like this:
Code:
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(25, 385, 130, 25)];
button.buttonType = UIButtonTypeCustom;
button.backgroundColor = [UIColor blackColor];
button.titleLabel.font = [UIFont boldSystemFontOfSize: 12];
[button setTitle:@"title" forState:UIControlStateNormal];
[button addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside];
[myScrollView addSubview:button];
[button release];
Any ideas?
MACloop