简体   繁体   English

仪器报告错误的内存泄漏?

[英]Instruments reporting false memory leaks?

I ran Instruments on my iPad app to check for leaks. 我在iPad应用程序上运行仪器以检查是否漏气。 It found several "leaks" where an object was being retained in a method: 它在方法中保留对象的地方发现了几个“泄漏”:

alt text http://cl.ly/a85d3d8bdc6286c8de71/content 替代文字http://cl.ly/a85d3d8bdc6286c8de71/content

But these objects are released later in dealloc: 但是这些对象稍后会在dealloc中释放:

alt text http://cl.ly/a265f76a538ee55781df/content 替代文字http://cl.ly/a265f76a538ee55781df/content

Are these classified as false-positives? 这些被归类为假阳性吗?

Is self.detailPopover a property declared with retain? self.detailPopover是否是使用keep声明的属性? If so then the assignment self.detailPopover will result in the generated set method calling retain on the object returned from alloc that you already own. 如果是这样,那么赋值self.detailPopover将导致生成的set方法调用对您已经拥有的alloc返回的对象的保留。

If it is a retained property then remove self from the assignment so the set method is not called and your retain count will be correct. 如果它是保留属性,则从分配中删除self,这样就不会调用set方法,并且保留计数将是正确的。

Property* prop = [[Property alloc] init]; // retain count == 1 
self.property = prop; // retain count == 2 
[prop release]; // retain count == 1 

or avoid the generated set method and it's retain... 或避免生成set方法并保留它...

property = [[Property alloc] init]; // retain count == 1 

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

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