I want to figure out in which cases I need to care about memory management when it comes to properties. I wrote down something from a site I don't remember anymore, where they said that if a property has any value other than NSNumber or NSValue, and if it has no setter, then UIKit would autorelease the old value and retain the new one. Although I dont get it why UIKit would set anything if there is no setter (directly to the value, I guess).
views:
623answers:
2
A:
If the property is declared as:
@property(retain) NSString *prop;
It will release the old value when you assign a new one.
However, make sure you release it on your dealloc method as well:
- (void)dealloc {
[prop release];
[super dealloc];
}
pgb
2009-04-24 14:53:14
A:
You should (re)read the Memory Management Guide for Cocoa. The memory management rules for properties are the same as for all other objects.
Barry Wark
2009-04-24 14:59:51