Skip to content

Commit

Permalink
fixed another crash with global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDesiatov committed Jan 20, 2013
1 parent 5bfcc9c commit 676ff62
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/TD_DatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ @implementation TD_DatabaseManager

+ (void) initialize {
if (self == [TD_DatabaseManager class]) {
kIllegalNameChars = [[NSCharacterSet characterSetWithCharactersInString: kLegalChars]
invertedSet];
// using -[NSObject copy] here because of crash, other people also do this, see
// http://stackoverflow.com/questions/10733698/static-objects-initialized-within-class-methods-in-arc
kIllegalNameChars = [[[NSCharacterSet characterSetWithCharactersInString: kLegalChars]
invertedSet] copy];
}
}

Expand Down

1 comment on commit 676ff62

@snej
Copy link

@snej snej commented on 676ff62 Jan 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't necessary. If you look closely at the StackOverflow thread you linked to, you'll see that the OP updated his post to say that the real problem was that one of his configurations was building without ARC.

With ARC the -copy call will have no effect because (a) NSCharacterSet is immutable, and (b) the compiler will see it and omit the -retain it would otherwise have generated when assigning to the strong property, so the refcount will be the same as it would have been.

Please sign in to comment.