I’m just updating an app of mine, and I found some old code that raised my eyebrows. My commenting is normally pretty verbose but I didn’t explain to myself why I did this.
I’m presenting a ModalView and updating the title and UITextField, like so:
addStoryItem.placeholderText = @"Foo"; //The text is always a static string.
addStoryItem.modalTitleText = @"Bar";
In the modal, the properties are assigned for both of these values:
@property (readwrite, assign) NSString *placeholderText;
@property (readwrite, assign) NSString *modalTitleText;
And then released in the modal’s dealloc after the modal is dismissed:
[placeholderText release];
[modalTitleText release];
Is this safe/wise/ok? I think I might have done this to avoid a retain cycle.
You broke a couple of rules:
You justify this with avoiding retain cycles. But since strings do not (usually) refer to other objects, cycles are not an issue here.