sangony
sangony

Reputation: 11696

UIButton released from memory?

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.

  1. If I delete a button from the array, does the button automatically get released from memory?
  2. If the answer to the above is no, what do I have to do to get it released from memory?

Upvotes: 0

Views: 190

Answers (2)

Stavash
Stavash

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

Cyrille
Cyrille

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

Related Questions