I have a category on NSString:

```
- (CGSize) agb_sizeWithFont:(UIFont *)font width:(CGFloat)width lineBreakMode:(NSLineBreakMode)lineBreakMode {
    if (!font) return CGSizeZero;

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = lineBreakMode;
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil];

    // this line is not threadsafe
    NSAttributedString *as = [[NSAttributedString alloc] initWithString:self attributes:attributes];

    CGRect bounds = [as boundingRectWithSize:CGSizeMake(width, 10000) options:(NSStringDrawingUsesLineFragmentOrigin) context:nil];
    return CGSizeMake(width, bounds.size.height);
}

```

I've observed intermittent `EXC_BAD_ACCESS` crashes when running this code on multiple threads (sometimes in `initWithString: attributes:`, sometimes in `boundingRectWithSize:options:context:`).

I believe my code is not thread-safe because `self` might deallocate on one thread while `initWithString: attributes:` is executing on the other.

1. Is my conclusion about this method's thread safety correct?
2. Would this code make it thread-safe?

```
NSString *strongSelf = self;
NSAttributedString *as = [[NSAttributedString alloc] initWithString:strongSelf attributes:attributes];

```

(By maintaining a reference to `self`, I attempt to ensure the object in memory is not deallocated while I'm using it.)
3. Is there any way to declare this method as *not thread-safe*? I'd love to generate a warning, for example, if a string declared as a `nonatomic` property is passed into this method.

Note: In case it's not obvious, I'm using ARC.