Reputation: 1478
I'm sure the static analyser is probably right in this case, but I don't quite understand why...
Here's a segment of code from a UUID class:
@interface UUID {
CFUUIDRef uuidRef;
}
@end
@implementation UUID
- (id) initWithString:(NSString*)string {
if (string && [NSNull null] != (NSNull*)string)
return [self initWithCFUUID:CFUUIDCreateFromString(kCFAllocatorDefault, (__bridge CFStringRef) string)];
else
return nil;
}
- (id) initWithCFUUID:(CFUUIDRef)uuidRef {
if (self = [super init]) {
self->uuid = uuidRef;
}
return self;
}
@end
Xcode has reported a leak on the 'return' line in the first init. A screenshot can be found here.
I have a basic understanding of bridge, bridge_retain, and bridge_transfer, but I believe bridge to be the right choice in this case.
If my understanding is correct, can anyone advise as to whether I am doing this incorrectly? Also, how would I go about resolving this?
Regards, Nick
Upvotes: 2
Views: 513
Reputation: 726839
You need to add dealloc
to your implementation, and call CFRelease on uuidRef
there:
- (void)dealloc
{
CFRelease(uuidRef);
}
Upvotes: 1