Re: proper way to release a static NSMutableDictionary?
Re: proper way to release a static NSMutableDictionary?
- Subject: Re: proper way to release a static NSMutableDictionary?
- From: Graham Cox <email@hidden>
- Date: Tue, 16 Dec 2008 10:45:12 +1100
On 16 Dec 2008, at 10:27 am, John Michael Zorko wrote:
I'm not concerned about the contents per se -- i'm concerned about
releasing something I declared as static, just to create it again
later. Part of me is saying "just release the dictionary's
contents, not the dictionary itself".
Can you explain why you think this a problem? I often release and
recreate static objects, at other times I also just remove all the
contents. It depends what you're trying to do. The 'static' nature of
an object doesn't seem relevant, but you didn't really give enough
context.
If you do release the object and don't immediately recreate it, I
would set the variable to nil however - that way you can tell that you
need to recreate the object.
Also, I this won't work:
static NSMutableDictionary *lookup = [NSMutableDictionary new];
You'll get the error 'initializer is not constant'
You can't run code as part of a static initializer, you can only
assign a constant value. So usually you'd do this:
static NSMutableDictionary* lookup = nil;
Then when you first use the dictionary, detect nil and allocate it then.
hth,
Graham
_______________________________________________
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