Re: Crash when calling custom methods in custom subclass.
Re: Crash when calling custom methods in custom subclass.
- Subject: Re: Crash when calling custom methods in custom subclass.
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 30 Jul 2005 14:30:52 -0700
On Jul 30, 2005, at 1:01 PM, mmalcolm crawford wrote:
> - (void) setContent: (NSString *)newContent
> {
> [_content release];
> _content = [newContent copy];
> }
It's not clear why you're not following the implementation pattern
clearly set out in the documentation and in other references?
The closest the documentation gets to this pattern would be:
- (void) setContent: (NSString *)newContent
{
[_content autorelease];
_content = [newContent copy];
}
Note, autorelease, not release.
The document I referred to in my previous reply, however, illustrates
the appropriate implementations of accessor methods for a collection:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
ModelObjects/Articles/moAccessorMethods.html>
If (as appears to be the case) you intend that the array be mutable,
note the use of 'mutableCopy':
- (void)setEmployees:(NSMutableArray *)newEmployees
{
if (employees != newEmployees) {
[employees autorelease];
employees = [newEmployees mutableCopy];
}
}
Unfortunately, I have tried learning from books, but find that I
learn much better by analyzing examples. While I will look for the
book you've suggested, if anyone could point out what I've done
wrong, and perhaps provide me with an example of a proper setter,
I'd greatly appreciate it.
There are clearly limitations to this approach. Im particular, given
examples of proper setters, you should ensure that you follow them.
The rules for memory management are not difficult, it is worth the
investment of time in leaning them -- see, for example:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
MemoryMgmt/Concepts/ObjectOwnership.html>
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden