views:

26

answers:

1

I have below code in a IBAction linked to a UIButton to change the background image on Button Click.

    UIImage *imageGreen=[UIImage imageNamed:@"bgGreen.png"];
 [clickButton setBackgroundImage:imageGreen forState:UIControlStateNormal];
 [imageGreen release];

after clicking the button three times it crashes the app in iPhone Simulator 4.0. I am alreading releasing the imageGreen object, what else can i do to prevent this.

A: 

No, you should not release imageGreen.

This variable is received with a convenient method, thus will autorelease itself. Calling -release will cause double-release error and crash the program.

Please read the memory management guide.

KennyTM
thanks kenny, i removed the release statement and it works just fine now.