I’m just learning Objective C, so I’m probably missing something, but the below code is a leak, right?
Taken from apple’s docs:
- (NSString*) title {
return [[title retain] autorelease];
}
- (void) setTitle: (NSString*) newTitle {
if (title != newTitle) {
[title release];
title = [newTitle retain]; // Or copy, depending on your needs.
}
}
The getter retains and autoreleases (cancelling each other out), but the setter retains also. That stops the reference count from ever reaching 0, right? What am I missing?
What you’re missing (because it’s not shown in the example) is that there will be a
releasefor all retained properties in the object’sdeallocmethod.