Re: I'm having trouble retaining a NSColor
Re: I'm having trouble retaining a NSColor
- Subject: Re: I'm having trouble retaining a NSColor
- From: Andy Lee <email@hidden>
- Date: Tue, 29 Aug 2006 09:33:41 -0400
On Aug 28, 2006, at 2:02 PM, Alan Smith wrote:
Here is the code where the color is retained:
- (void)setHighlightColor:(NSColor*)color
{
[highlightColor release];
if (color != nil)
{
highlightColor = [color retain];
}
}
I don't know if it's related to your crashes, but this code has a
bug. I've removed to NSLog() statements to make it clearer.
Suppose highlightColor == color, meaning both variables point to the
same chunk of memory. If highlightColor's retain count is 1, the
release will cause that chunk of memory to be freed, so both
variables will be dangling pointers. You then proceed to save that
bad pointer in your highlightColor instance variable.
On Aug 28, 2006, at 9:06 PM, Alan Smith wrote:
What do you
mean by "accessors"?
Accessors are getter and setter methods for your object's instance
variables -- really for any attributes of your object, but the vast
majority of the time this means instance variables.
I did read I. Savant replies and I fixed that. It didn't solve the
problem.
Did you also read Matt's advice about using tried and true memory
management patterns? Shawn gave examples. Take a while to figure
out why those patterns don't have the bug your code has. Then pick
one and memorize it so you can type it without having to think about
it. Or better yet, try Accessorizer.
--Andy
_______________________________________________
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