« Limiting Stacksize for recursion debugging | Main

-[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];

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on September 21, 2008 5:23 PM.

The previous post in this blog was Limiting Stacksize for recursion debugging.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.34