Reputation: 11696
I create a couple of UIButtons (with selectors) in a method (throughout the life cycle of the app) and stick them all into an NSMutableArray. The created buttons are NOT properties but the array is.
Upvotes: 0
Views: 190
Reputation: 14304
The button will indeed, eventually, be released from memory as no one is retaining it. Its retain count will be decremented regardless, but only if no one else is retaining it, it will be released from memory.
This is however a somewhat confusing mechanism - keep in mind that the UIButtons are views and are probably a part of your view hierarchy which also retains them. If they're also visible, they must be removed from their superview in order to be released.
Upvotes: 1
Reputation: 25144
Anything you put in a NSArray
(and a NSMutableArray
) gets retained by the array, and released when removed from the array or when the array itself is released. It's true for buttons and any other object.
Upvotes: 1