简体   繁体   中英

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.

Here my question is what is the different BWN [self.object release] and just [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] . 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];

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. And result will depend whether the property is defined as assign / copy / retain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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