• 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: NSMutableDictionary not sending release message to contained objects at dealloc time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableDictionary not sending release message to contained objects at dealloc time


  • Subject: Re: NSMutableDictionary not sending release message to contained objects at dealloc time
  • From: publiclook <email@hidden>
  • Date: Sat, 12 Apr 2003 08:26:53 -0400

Are you deliberately being dense ? NSMutableArray and NDMutableDictionary behave exactly the same with regard to retaining and releasing their contents. RTFM for gods sake. You have gone around and around on this subject and you either refuse to read what people write or you are a troll. This is SIMPLE.

Add an object to a collection an the object is retained by the collection.
Remove an object from a collection and the object is released by the collection.
When a collection is deallocated, it releases all objects it contains.

- Allocate collection object A. Its retain count is 1
- Add collection object A to collection B. A's retain count is 2 regardless of B's retain count.
- Add any number of objects to A.
- Remove A from B. A's retain count is 1.
- None of the objects previously added to A are released because they have not been removed from A and A has not been deallocated.


On Friday, April 11, 2003, at 07:02 PM, Greg Hurrell wrote:

El Saturday, 12 Apr, 2003, a las 00:45 Australia/Adelaide, Greg Titus escribis:

No, absolutely not. The contents of the dictionary should be sent a release message when the dictionary itself is _dealloced_, to balance the retain message they are sent when added to the dictionary. If you retain the dictionary 10 times, it doesn't retain each object inside the dictionary 10 times - those objects were retained _once_ when they were added to the dictionary in the first place. If you then release the dictionary 10 times, each object inside the dictionary is unaffected. It is only when the dictionary itself is deallocated (retain count goes to zero) that it is emptied and every object inside it receives a single release.

Fair enough... My misunderstanding hinged on my belief that collection classes like NSMutableDictionary and NSMutableArray would behave the same.

Both send a retain as objects are added.

Yet while array sends a release when objects are removed, the dict only sends a release when it itself is deallocated (according to you, and I defer to your experience on this one!) Why the discrepancy in behaviour?

Cheers
Greg
_______________________________________________
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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSMutableDictionary not sending release message to contained objects at dealloc time
      • From: Greg Hurrell <email@hidden>
References: 
 >Re: NSMutableDictionary not sending release message to contained objects at dealloc time (From: Greg Hurrell <email@hidden>)

  • Prev by Date: Access NetCDF library
  • Next by Date: Re: How to clear an NSImage
  • Previous by thread: Re: NSMutableDictionary not sending release message to contained objects at dealloc time
  • Next by thread: Re: NSMutableDictionary not sending release message to contained objects at dealloc time
  • Index(es):
    • Date
    • Thread