Re: local statics, GC, and strong references
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