Does anyone know why this could be happening?
The error clearly says that it’s trying to access objectForKey of a dictionary that has been deallocated. However in the stack trace I don’t see any dictionary. How is this possible?
So here’s the code:
-(CGSize)sizeConstrainedToSize:(CGSize)maxSize fitRange:(NSRange*)fitRange {
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)self);
CFRange fitCFRange = CFRangeMake(0,0);
CGSize sz = CTFramesetterSuggestFrameSizeWithConstraints(framesetter,CFRangeMake(0,0),NULL,maxSize,&fitCFRange);
if (framesetter) CFRelease(framesetter);
if (fitRange) *fitRange = NSMakeRange(fitCFRange.location, fitCFRange.length);
return CGSizeMake( floorf(sz.width+1) , floorf(sz.height+1) ); // take 1pt of margin for security
}
UPDATE:
Turns out this is a problem on NSCache:
@implementation NSCache (SharedCache)
+(NSCache*)sharedCache;
{
static NSCache* sharedCache = nil;
if (sharedCache == nil) {
sharedCache = [[[self alloc] init] retain];
[sharedCache setCountLimit:0];
}
return sharedCache;
}
if I removed the retain there it crashes..
it basically crashes here:
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)self);
with that exception.

One of the properties or member variables is or contains a dictionary which has been deallocated. You might have code that is setting an attributes dictionary on the attributed string which is being over released.
Ultimately, the code you are highlighting is identifying an over released object but is not the crashing code. You need to find where the object is being over released. I recommend using Xcode performance tools, specifically the Zombies tool, to identify this crash. It’s simulator only though so this will need to be reproduceable in the simulator to use the zombies tool.