i know this issue was discussed many times before , but i have a simple question.
after reading all the apple’s rules to manage the memory, i know this :
if i allocate an object , i own it and have to release it . so i have to do :
ran *me = [[ran alloc] init];
//do somthing
[me release];
so now , the retain count is 0, after i release ran object.
BUT i was also read that when retain count of an object is 0, the dealloc method is being invoked .
so my question is, after i took down the retain count to 0, DO i have to release again the object at the dealloc?
-(void)dealloc
[me release];
or that the first release did the job ?
otherwise, why dealloc is being called anyway ? if the retain count=0 we are ok no ??
thanks a lot .
No, you do not need to release again in there – in fact, don’t do it!
The reason dealloc is being called is so that clean-up may occur. For example, if you allocated memory in your class, you can free it up there. And remember that the retain count could reach 2, 3, 4, 5…. so just because a
releaseis done, you don’t (as an outside user of the class) know that the dealloc should be called. That’s how it is different than a release.One thing to note is that the dealloc method may not be immediately run when the count hits 0. It could be done much later.