Cocoanetics/DTCoreText — Issue #96: character-set auto release issue
Author: TomSwift
Created: 2011-12-30 20:33:15+00:00
State: open

Perhaps I'm doing something wrong, but in my app the various NSCharacterSets maintained by DTCoreText are being auto-released and causing crashes when they're subsequently accessed.

I *think* the fix is to retain each character set when it is created, like this:

+ (NSCharacterSet *)cssStyleAttributeNameCharacterSet
{
static dispatch_once_t predicate;

dispatch_once(&predicate, ^{
_cssStyleAttributeNameCharacterSet = [[NSCharacterSet characterSetWithCharactersInString:@"-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"] retain];
});
return _cssStyleAttributeNameCharacterSet;
}

The "dispatch_once" is new to me. But I presume the dispatch happens the first time the method is called, afnd the characterset will be created inside whatever auto-release pool is current at that time. When that pool flushes, bye bye characterset...