objective c - What happens if we make an allocated pointer to an object as nil? -
objective c - What happens if we make an allocated pointer to an object as nil? -
i have seen code in couple of places.
xyz *xyz = [[xyz alloc] init];
but in dealloc instead of [xyz release]
;
people have used self.xyz = nil
;
won't cause memory leak?
edit : not xyz = nil
wrote initially, self.xyz = nil
, property.
yes, memory leak, if xyz declared property eg
@property (nonatomic, retain) xyz* xyz; - (void)dealloc { self.xyz = nil; [super dealloc]; }
this not memory leak, maybe ones saw this?
edit: not memory leak, reason being, setter created property, it'll similar 1 below
- (void)setxyz:(xyz *)newxyz { [xyz release]; xyz = [newxyz retain]; }
because newxyz nil, sending retain nil nothing, while old xyz beingness released setter. memory managed in case
objective-c
Comments
Post a Comment