Sunday, October 05, 2008

iPhone dev 16 - memory management

Found an article about the memory management issues. Noticed that I am indeed making a mistake. After allocing and initing an object, I am increasing the retain count by one. This is not necessary, the retain count is already one at this point.

Second mistake I think I am making is failing to release my textfielddelegate and UITextField. Maybe I could use autorelease?

But what happens when I set the delegate by doing testText.delegate = x. Is the retain count of x now incremented by the delegate setter method? In API docs it shows that the property is declared like so:
@property(assign) id delegate

"assign Specifies that the setter uses simple assignment. This is the default."

Okay, so it would seem that the retain count does not get incremented, which means it is my responsibility to release the object at the end. Great, seems to work!