• 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: Retain counts with a dictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Retain counts with a dictionary


  • Subject: Re: Retain counts with a dictionary
  • From: Sherm Pendley <email@hidden>
  • Date: Sun, 16 Mar 2003 08:33:45 -0500

On Saturday, March 15, 2003, at 08:25 PM, Jeffrey Mattox wrote:

I am using an NSMutableDictionary as an associative array (a la, a Perl hash, I'm in heaven :-).

You do know you can program Cocoa in Perl, right? ;-)

<http://camelbones.sourceforge.net>

1. What I am seeing, however, is that if theKey is new, it's retain count after being copied becomes 2. (If theKey is not new, it's retain count stays at 1.) Why is the key's retain count incremented if the key is just copied?

When the documentation says that theKey is copied, what it means is that a "copy" message is sent to theKey, and the return value from that is stored in the dictionary. What you're seeing is the result of how NSString implements its copy method. Because NSString objects are immutable, there's no reason to make an actual copy; so, NSString's copy method simply increments the retain count and returns self.

2. Is it okay to use @"" for the objects in the loop? Will that create a new null string for each addition, or reuse the same one? Is there a better way?

You could use the shared instance of the NSNull class. As in:

[theDictionary setObject: [NSNull null] forKey: theKey];

sherm--


"But i don't want to go among mad people," Alice remarked.
"Oh, you can't help that," said the Cat: "we're all mad here. I'm mad, You're mad."
"How do you know I'm mad?" said Alice.
"You must be," said the Cat, "or you wouldn't have come here."
"Alice in Wonderland" - Lewis Carrol
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Retain counts with a dictionary (From: Jeffrey Mattox <email@hidden>)

  • Prev by Date: Re: Trouble with a save panel
  • Next by Date: Re: Trouble with a save panel
  • Previous by thread: Re: Retain counts with a dictionary
  • Next by thread: Retain counts with a dictionary
  • Index(es):
    • Date
    • Thread