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: Matt Neuburg <email@hidden>
- Date: Mon, 28 Aug 2006 11:27:31 -0700
- Thread-topic: I'm having trouble retaining a NSColor
On Mon, 28 Aug 2006 14:02:53 -0400, "Alan Smith" <email@hidden>
said:
>- (void)setHighlightColor:(NSColor*)color
>{
> [highlightColor release];
>
> if (color != nil)
> {
> NSLog(@"before HEBrowserCell retains color, its retain count
>equals: %i", [color retainCount]);
> highlightColor = [color retain];
> NSLog(@"after HEBrowserCell retains color, its retain count
>equals: %i", [color retainCount]);
> }
>
> NSLog(@"highlightColor = %@", highlightColor);
>}
Yipes! And suppose "color" *is* nil - you've now released highlightColor but
you've given the pointer to it no value. So the pointer is now pointing at
junk.
Do not, not, NOT try to make up your own memory management patterns. Use the
tried and true patterns. (I'm not going to try to explain what they are,
because mmalc's list rules includes an adjuration not to attempt an
independent summary of memory management.)
m.
PS And don't look at retainCount. Just manage memory correctly.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
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