GC bug in NSFontManager?
GC bug in NSFontManager?
- Subject: GC bug in NSFontManager?
- From: Ross Carter <email@hidden>
- Date: Tue, 30 Jun 2009 14:34:48 -0400
I am receiving crash reports for code that enumerates an array
returned by NSFontManager. The app is garbage-collected.
The crashes occur at various places in my code, but always while I am
enumerating a NSFontManager array. Here is the code for one group of
crashes, with the crash points marked:
- (NSDictionary *)fontNamesFamiliesDictionary {
NSMutableDictionary *returnVal = [NSMutableDictionary dictionary];
NSFontManager *fm = [NSFontManager sharedFontManager];
NSArray *familyNames = [fm availableFontFamilies];
NSString *familyName;
for (familyName in familyNames) {
// ************** This line causes a EXC_BAD_ACCESS:
NSArray *memberDescriptions = [fm
availableMembersOfFontFamily:familyName];
NSArray *memberDescription;
for (memberDescription in memberDescriptions) {
// ******* This line causes unrecognized selector -objectAtIndex
sent to NSString or NSCTFontDescriptor:
NSString *fontName = [memberDescription objectAtIndex:0];
if (fontName != nil) {
[returnVal setObject:familyName forKey:fontName];
}
}
}
return returnVal;
}
The two NSFontManager methods that are implicated are -
availableMembersOfFontFamily: and -availableFontFamilies:.
The nature of the crashes suggests that a message is being sent to a
released object, leading me to suspect that this is a GC bug.
The Garbage Collection guide contains this remark concerning fonts:
"Leaked but not lost objects
"Cocoa used to have several classes of object (fonts and images) where
a global table of strong keys held weak value references to the
objects. The object would remove itself from the global table on
dealloc. But it would also be the case that there would be some
universally known objects that never went away, and the pattern was to
allocate these at startup using [[alloc ] init] and simply place them
in the weak table. The reference count for these objects would never
decrease and so they would live indefinitely. Under garbage
collection, in the absence of a strong reference these universal
objects are collected. The solution is to use [[NSGarbageCollector
defaultCollector] disableCollectorForPointer:object] on these objects
before placing them in the weak table."
That's all over my head. It's just enough to make me wonder, when I
enumerate an array returned by NSFont Manager, is it possible that the
array or its members are getting collected during the enumeration?
(I tried to file a radar, but the bug reporter is acting up again
today.)
Ross Carter
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden