Q:

Memory Leak in NSString+URLEncoding

I ran the instruments in my app and saw some memory leaks in a category for NSString, NSString+URLEncoding:
- (NSString *)urlEncodedString {

    return (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                        (__bridge CFStringRef)self,
                                                                        NULL,
                                                                        (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
                                                                        kCFStringEncodingUTF8);
}

- (NSString *)urlDecodedString {

    return (__bridge NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,
                                                                                        (__bridge CFStringRef)self,
                                                                                        (CFStringRef)@"",
                                                                                        kCFStringEncodingUTF8);
}.

I'm using ARC.

A:

Edgar, see Evernote's implementation for NSString+URLEncoding available in GitHub here.
You should use __bridge_transfer if you want ARC to release the object for you.
If you still want to maintain __bridge you must release the object manually.

