• 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: Raphael Sebbe <email@hidden>
  • Date: Thu, 10 Apr 2003 16:26:10 +0200

I would say that it tells they are autoreleased. More, constant Obj C strings (defined as @"") are never deallocated.

Raphael

On Thursday, April 10, 2003, at 04:10 PM, Greg Hurrell wrote:

Just noted weird bug.

I have an NSMutableDictionary that gets added to an NSMutableArray.

When I remove the dictionary, it gets a release message, and deallocates itself (good).

But the dictionary doesn't send release messages to all ITS contents, and so they leak (bad)!

It seems selective though. Witness the following sample code:

// put an autoreleased object in the dictionary, then the dictionary in the array
NSString *str = @"An autoreleased string";
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:str, @"Key", nil];
NSMutableArray *arr = [[NSMutableArray arrayWithObjects:dict, nil];

NSLog(@"Retain count on string is %d", [str retainCount]); // count is 2 (correct)

// remove the dictionary, which should send release to str as well
[arr removeObjectAtIndex:0];

NSLog(@"Retain count on string is %d", [str retainCount]); // count is 1 (correct)


Now for the same code but instead of an autoreleased object we'll put in something like a non-autoreleased NSObject subclass:

MYObject *obj = [[MYObject alloc] init];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:obj, @"Key", nil];
NSMutableArray *arr = [[NSMutableArray arrayWithObjects:dict, nil];

NSLog(@"Retain count on obj is %d", [obj retainCount]); // count is 2 (correct)

// remove the dictionary, which should send release to obj as well
[arr removeObjectAtIndex:0];

NSLog(@"Retain count on obj is %d", [obj retainCount]); // count is still 2 (INCORRECT!)



Can anyone explain this mystery?
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.

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

  • Prev by Date: NSMutableDictionary not sending release message to contained objects at dealloc time
  • Next by Date: How to do a custom cell highlighting…
  • Previous by thread: 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