• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Crash when calling custom methods in custom subclass.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Crash when calling custom methods in custom subclass.
      • From: mmalcolm crawford <email@hidden>
References: 
 >Crash when calling custom methods in custom subclass. (From: Adam Raney <email@hidden>)
 >Re: Crash when calling custom methods in custom subclass. (From: Charilaos Skiadas <email@hidden>)
 >Re: Crash when calling custom methods in custom subclass. (From: Adam Raney <email@hidden>)
 >Re: Crash when calling custom methods in custom subclass. (From: Adam Raney <email@hidden>)
 >Re: Crash when calling custom methods in custom subclass. (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Catching a click during a loop
  • Next by Date: Re: Catching a click during a loop
  • Previous by thread: Re: Crash when calling custom methods in custom subclass.
  • Next by thread: Re: Crash when calling custom methods in custom subclass.
  • Index(es):
    • Date
    • Thread