本文介绍了修复ARC中潜在的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下单例类(SharedManager)辅助方法可能导致保留周期。在静态分析器中收到警告:在线路上分配的对象的潜在泄漏......我该如何解决?

The following singleton class (SharedManager) helper method might be causing a retain cycle. Getting warnings in static analyzer: "Potential leak of an object allocated at line ..." How can I fix?

我确实试过制作ivar uuid __weak但是当我分析时仍会出现警告。

I did try making ivar uuid __weak but warning still appears when I analyze.

    NSString  *__weak uuid =  (__bridge NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject);

谢谢

在课堂上被叫像这样:

myUUID = [SharedManager generateUUID];



+ (NSString *)generateUUID
{

 CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault);
 NSString  *uuid =  (__bridge NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject);
CFRelease(uuidObject);

  return uuid;

}


推荐答案

NSString  *uuid =  (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject);

这会删除警告吗?

这篇关于修复ARC中潜在的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 22:33