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 (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