Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crash when calling custom methods in custom subclass.




On Jul 30, 2005, at 12:01 PM, Adam Raney wrote:

Also taking your advice, my setters now utilize this format:

- (void) setContent: (NSString *)newContent
{
[_content release];
_content = [newContent copy];
}


Adam, I'm not sure whose advice you're referring to, but the setter above is a potential crasher. If newContent is the same object you've already got in _content, then when you release it, it may be destroyed immediately. If that happens, then [newContent copy] will crash your app, since you'll be trying to send a -copy message to a freed object.

Also, you shouldn't use leading underscores in your ivar names.

-jcr


John C. Randolph <email@hidden> (408) 914-0013 Roaming Cocoa Engineer, Available for your projects at great Expense and Inconvenience.



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to 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>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.