• 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: I'm having trouble retaining a NSColor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I'm having trouble retaining a NSColor


  • Subject: Re: I'm having trouble retaining a NSColor
  • From: "I. Savant" <email@hidden>
  • Date: Mon, 28 Aug 2006 14:14:40 -0400


Also, never rely on retain count. You have no idea what the hidden Cocoa machinery might be doing with your object behind the scenes. Therefore the actual retain count is ... not necessarily reliable for debugging. :-)


--
I.S.


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)
   {
       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);
}

- (NSColor *)highlightColorInView:(NSView *)controlView
{
   NSLog(@"highlightColor = %", [highlightColor retainCount]);
   return highlightColor;
}

Here is the code where the color is passed in:

[cell setHighlightColor: [NSColor colorWithCalibratedRed: 0.2941
green: 0.5824 blue: 0.8706 alpha: 1.0]];

And this is the output:

before HEBrowserCell retains color, its retain count equals: 1
after HEBrowserCell retains color, its retain count equals: 2
highlightColor = NSCalibratedRGBColorSpace 0.2941 0.5824 0.8706 1

That's all well and good but, when the code gets to the third log
message it crashes. All I wanted was to verifiy that the color existed
and it crashes.

Obviously I'm missing something.

All help is appreciated, Alan

P.S. I tried: highlightColor = [color copy]; but it makes no difference.
--
// Quotes from yours truly -------------------------
"You don't forget, you just don't remember."
"Maturity resides in the mind."
"Silence is the Universe's greatest gift."
"Don't waste your life doing things others have already done."
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden

_______________________________________________ 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
References: 
 >I'm having trouble retaining a NSColor (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: I'm having trouble retaining a NSColor
  • Next by Date: Re: changing "document" terminology for AppleScript support
  • Previous by thread: Re: I'm having trouble retaining a NSColor
  • Next by thread: Re: I'm having trouble retaining a NSColor
  • Index(es):
    • Date
    • Thread