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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to