• 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: proper way to release a static NSMutableDictionary?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: proper way to release a static NSMutableDictionary?


  • Subject: Re: proper way to release a static NSMutableDictionary?
  • From: Ken Thomases <email@hidden>
  • Date: Mon, 15 Dec 2008 17:46:47 -0600

On Dec 15, 2008, at 5:33 PM, Andrew Farmer wrote:

On 15 Dec 08, at 14:54, John Michael Zorko wrote:
Imagine this:

static NSMutableDictionary *lookup = [NSMutableDictionary new];

... now imagine a situation where I need to clear that dictionary. If I call

[lookup release];
lookup = [NSMutableDictionary new];

... it will obviously be faster than coding a for loop and removing each object in the dictionary, but since it was declared as static, which is safer?

Neither. All that "static" means on a global variable is that the symbol isn't visible from other source files. It has no bearing whatsoever on the contents of that variable.

Although all global variables have static storage, quite aside from the "static" keyword.


Perhaps John is confused about what is static in this case, though. The storage for lookup, which is a pointer, is static. The mutable dictionary object it points to, though, is not. It's allocated from the heap.

I'm guessing that John is coming from C++ where you can truly have statically allocated objects. If you do that, then it's wrong to use the delete operator on such an object. But that's not analogous to this case.

Regards,
Ken

_______________________________________________

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


References: 
 >proper way to release a static NSMutableDictionary? (From: John Michael Zorko <email@hidden>)
 >Re: proper way to release a static NSMutableDictionary? (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: proper way to release a static NSMutableDictionary?
  • Next by Date: Re: Where is the Computer Image ?
  • Previous by thread: Re: proper way to release a static NSMutableDictionary?
  • Next by thread: Re: proper way to release a static NSMutableDictionary?
  • Index(es):
    • Date
    • Thread