【问题标题】:why does "[[UIDevice currentDevice] identifierForVendor]"cause memory leak?为什么“[[UIDevice currentDevice] identifierForVendor]”会导致内存泄漏?
【发布时间】:2015-06-17 01:54:34
【问题描述】:

我正在使用 x-code 6.3 工具来分析我的应用程序,但我不明白为什么这条线会导致内存泄漏:

+ (NSString*)IDFV
{
    NSUUID* device_id = [[UIDevice currentDevice] identifierForVendor];// !100%
    return [device_id UUIDString];
}

我想发布一张图片,但没有足够的声誉。

我选择了instruments-leaks-call tr​​ee,然后选择'invert call tr​​ee'和'hide system libraries',然后我得到了上面显示的泄漏代码之一,有人可以帮忙,谢谢。

【问题讨论】:

    标签: ios memory-leaks


    【解决方案1】:

    它并没有泄漏内存这样

    UIDevice currentDevice 返回一个单例 - 也就是说,对 currentDevice 的每个后续调用都将返回对同一对象实例的引用。

    此单例实例在第一次调用 currentDevice 时分配,并且此对象将保持分配状态,直到您的应用退出。

    这显示为“泄漏”(从技术上讲是泄漏,因为对象永远无法释放)但这是设计使然,无需担心。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多