[英]Static Analyzer - Memory Leak
In Xcode while releasing the object in dealloc method by like [self.object release] this line is shown as memory leak using static code analyzer but it not showing as leak while running instruments. 在Xcode中,像[self.object release]一样,在dealloc方法中释放对象时,使用静态代码分析器将该行显示为内存泄漏,但在运行仪器时未显示为泄漏。
Here my question is what is the different BWN [self.object release]
and just [object release]
在这里,我的问题是BWN
[self.object release]
和[object release]
有何不同?
Please clarify this, 请澄清一下
Thanks in advance. 提前致谢。
self.object
actually calls the getter method ( [self object]
), which returns the instance variable object
(or depending how is synthesized), but the instance variable actually holds the retained object, so you must do [object release]
. self.object
实际上调用getter方法( [self object]
),该方法返回实例变量object
(或取决于合成方式),但是实例变量实际上包含保留的对象,因此必须执行[object release]
。 It's good practice to synthesize your properties with: @synthesize object = _object
so you don't get confused of the property and the instance variable - your property will be self.object
, but the instance variable will be _object
and you will call [_object release];
这是一个与合成的性能很好的做法:
@synthesize object = _object
这样你就不会感到困惑的属性和实例变量的-你的财产将被self.object
,但实例变量将是_object
你要给[_object release];
instead of doing - 而不是-
[self.object release]
you need to do - 您需要做-
self.object = nil; or [object release];
[self.object release] will send the release call to the object returned by getter of property. [self.object release]将释放调用发送到属性的getter返回的对象。 And result will depend whether the property is defined as assign / copy / retain.
结果将取决于该属性是否定义为assign / copy / retain。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.