CFUUIDBytes可能导致iOS内存泄漏(Potential iOS memory leak with CFUUIDBytes)

编程入门 行业动态 更新时间:2024-10-28 12:16:40
CFUUIDBytes可能导致iOS内存泄漏(Potential iOS memory leak with CFUUIDBytes)

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

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

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

谢谢

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

最满意答案

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

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; }

更多推荐

本文发布于:2023-04-27 15:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内存   iOS   CFUUIDBytes   leak   memory

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!