3

我有一个静态方法定义如下:

+(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;

}

当我在我的项目上运行 Product->Analyze 时,用 //ISSUE 注释的行会引发以下问题:

Potential leak of an object alocated on line 23 and stored into 'originalUuid'

我做错了什么,我该如何解决?

谢谢

4

1 回答 1

4

即使您使用 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;

}
于 2012-10-17T15:08:29.357 回答