- (Void) setCity: (NSString *) c {
[C retain] ;/ / --- 1
[City release] ;/ / --- 2
city = c ;/ / --- 3
}
This is a strong reference
The second line of code is to prevent the city may have been pointing to an object, if not the first of
city to conduct a release, while pointing directly to the city c pointed object, then the city may be the original object pointed out
Now a memory leak, because the city is changing point when there is no point to the original object reference counter is decremented by one, in violation
After you retain the object to release the object at the right time requirements.
But there never was a case of city retaincount other objects pointing to the default one then executes the second line after 0, went on to be recycled so that case the above code is wrong I do not know my conclusion right
Reply:
Who is who apply for release.
c retain, then you need to be will c release.
The second line city did not retain on release unreasonable.
The third line city = [c retain], back then release it.
No comments:
Post a Comment