• 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
GC bug in NSFontManager?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: GC bug in NSFontManager?
      • From: Quincey Morris <email@hidden>
    • Re: GC bug in NSFontManager?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Two threads, two managed object contexts. Do I need locking?
  • Next by Date: Re: NSBitMapRepresentation --> JPEG compression?
  • Previous by thread: Re: Clarification of NSPredicate constraints for Core Data SQL store
  • Next by thread: Re: GC bug in NSFontManager?
  • Index(es):
    • Date
    • Thread