views:

50

answers:

1

Hi,

I am using the this code in my iPhone application:

UIButton * MyButton=[UIButton ButtonWithType:UIButtonTypeRoundRect]retain];

If I don't use this retain will my app crash? What is the function of this retain?

+3  A: 

You should retain because the UIButton object returned from the call is autoreleased.

Claus Broch
This is correct, it's also worth remembering to release the object when you're done with it or you'll get a leak
djhworld
Any creation method that starts with a type i.e. string, array, button etc is a convenience method that returns an autoreleased object which will die the next time the pool is drained unless you retain it.
TechZen