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

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -