I have a question about memory management.
For example I have an iPhone application that uses multiply programmatically created views.
for example programmatically generated buttons.
UIButton *myButton=[UIButton alloc] initWithFrame:...; //etc
then, normally we add this button to subviews array:
[self.view addSubview:myButton];
then we releasing button.
[myButton release]
When I need to remove this button how can I keep track on this button in subviews array?
I know I can do this using tag property but I think exists another way to keep connection with it.
You can simply assign it to an instance variable:
You just need to be careful: as soon as you do something like
[myInstanceVariable removeFromSuperview];it might get deallocated immediately (if you haven’t retained it) and it would then point to invalid memory.