• 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: local statics, GC, and strong references
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: local statics, GC, and strong references


  • Subject: Re: local statics, GC, and strong references
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 31 Jul 2009 11:06:31 -0700

On Jul 31, 2009, at 10:30, Sean McBride wrote:

Is there anything wrong with the below, in a GC app?

- (void)drawRect:(NSRect)inRect
{
	// Create the colour only once.
	 static NSColor* colour = nil;
	 if (!colour)
	 {
		  colour = [NSColor colorWith...];
	 }

	[colour set];

 // Do drawing
}

Are there special rules or gotchas with local statics like 'colour'
above? Is 'colour' always safe to use where I try to send it the 'set'
message? Could it be already-collected/lack strong references to keep
it alive?

That pattern has always worked for me in 10.5. The static variable is a strong reference.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Fun (or not) with NSArrayControllers and CoreData.
  • Next by Date: Re: Stumped by EXEC_BAD_ACCESS
  • Previous by thread: Re: Application Preferences - a general question
  • Next by thread: How to change focus ring color?
  • Index(es):
    • Date
    • Thread