I have a static method defined as follows:
+(NSString*)getNewIdAsBase64
{
// Grab new uuid
CFUUIDRef originalUuid = CFUUIDCreate(nil);//create a new UUID
//NSLog(@"Step a: original uuidObj = %@",originalUuid);
CFUUIDBytes originalBytes = CFUUIDGetUUIDBytes (originalUuid);//ISSUE
NSData* data88 = [NSData dataWithBytes: &originalBytes length: sizeof(originalBytes)];
NSString* hugo = [data88 base64EncodedString];
return hugo;
}
When I run Product->Analyze on my project then the line commented with //ISSUE raises the following issue:
Potential leak of an object alocated on line 23 and stored into 'originalUuid'
What am I doing wrong, and how do I fix it?
Thanks
You will need to release the object you create even if you are using ARC:
+(NSString*)getNewIdAsBase64
{
// Grab new uuid
CFUUIDRef originalUuid = CFUUIDCreate(nil);//create a new UUID
//NSLog(@"Step a: original uuidObj = %@",originalUuid);
CFUUIDBytes originalBytes = CFUUIDGetUUIDBytes (originalUuid);//ISSUE
NSData* data88 = [NSData dataWithBytes: &originalBytes length: sizeof(originalBytes)];
NSString* hugo = [data88 base64EncodedString];
CFRelease(originalUuid);
return hugo;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.