简体   繁体   English

为什么“ [[UIDevice currentDevice] identifierForVendor]”会导致内存泄漏?

[英]why does “[[UIDevice currentDevice] identifierForVendor]”cause memory leak?

I am using x-code 6.3 instruments to analyze my application, but I don't understand why this line cause memory leak: 我正在使用x-code 6.3工具来分析我的应用程序,但是我不明白为什么这行会导致内存泄漏:

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

I wanted to post a picture but not enough reputations. 我想发布一张图片,但声誉不够。

iI chose instruments-leaks-call tree,and select 'invert call tree' and 'hide system libraries',then I got one of the leak codes shows above, can someone help,thanks. 我选择了仪器泄漏调用树,然后选择“反转调用树”和“隐藏系统库”,然后我得到了上面显示的泄漏代码之一,有人可以帮忙,谢谢。

It isn't leaking memory as such 它不会像这样泄漏内存

UIDevice currentDevice returns a singleton - that is, each subsequent call to currentDevice will return a reference to the same object instance. UIDevice currentDevice返回一个单例-也就是说,每次对currentDevice后续调用都将返回对同一对象实例的引用。

This singleton instance is allocated on the first call to currentDevice and this object will remain allocated until your app exits. 该单例实例是在第一次调用currentDevice分配的,并且此对象将保持分配状态,直到您的应用程序退出。

This shows up as a "leak" (and technically is a leak because the object can never be released) but this is by design and nothing to be concerned about. 这显示为“泄漏”(从技术上讲是泄漏,因为永远无法释放对象),但这是设计使然,无需担心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM