I have a form with various controls. One of these controls lets the user change the category of the form being submitted via a modal view that appears after tapping on the control. When the user makes a selection to change the category of the form, the form needs to re-display the controls based on the new category.
Other than removing the previous controls from the form’s view, is there anything I need to worry about in regards to the controls that are being discarded? Consider the following method that the form implements:
- (void)showControls
self.controls = [NSMutableArray array];
for(UIControl *control in self.dataSource.controls){
[self.controls addObject:control];
[self.view addSubview:control];
}
}
If I call this method multiple times (because the user changes the form category, as described earlier), I assume it results in various NSMutableArrays floating around without any pointers that reference them. Is this ok to do? I’m using ARC, so will it automatically collect those “lost” arrays?
ARC doesn’t “collect” anything. Also, what you’re doing there is fairly irrelevant that ARC is being used. You’re using the setter for the
controlproperty which will work in the same way as pre-ARC. It will release the old value and retain the new value. So, you shouldn’t have any problems with the arrays being “lost”, unless you do weird things withself.controlsother than what you’ve shown.