Nat! bio photo

Nat!

Senior Mull

Twitter Github Twitch

-[CFDictionary retain] bug

This is a strange one. I don't see anything illegal I am doing. NSMutableDictionary's real class is of course CFDictionary and that will be returned from class. But why is it going into recursion on retain ?

#import <Foundation/Foundation.h>


int main (int argc, const char * argv[]) 
{
   NSAutoreleasePool     *pool;
   NSMutableDictionary   *dict;
   NSMutableDictionary   *other;
   
   pool = [NSAutoreleasePool new];

   dict  = [NSMutableDictionary dictionary];
   other = [[[dict class] new] autorelease];
   
   NSLog( @"A");
   [other retain]; // Program received signal:  “EXC_BAD_ACCESS”.
   NSLog( @"B");
   
   [pool release];
   return( 0);
}

UPDATE: Thanks to Ken Ferry from the MacOSXDev mailing list, this piece of code can be made usable thusly:

   other = [[[dict classForCoder] new] autorelease];