When deallocing a refrence I've seenrelease
anddealloc
being used for example
-(void)dealloc
{
[foo release];
[nar dealloc];
[super dealloc];
}
My question is when isrelease
to be used and when isdealloc
to be used?
Thanks
转载自:http://stackoverflow.com/questions/559295/difference-between-release-and-dealloc-in-objective-c
When deallocing a refrence I've seen
My question is when is Thanks
| ||||
Never call If you're going to program Cocoa, you need to read theMemory Management Guidelines. It's incredibly simple once you get over the initial hump, and if you don't understand what's in that document, you'll have lots of subtle bugs. | |||||||
|
For the comment of accepted answer, it is not [self dealloc] it is [super dealloc] and he had meant to write [super dealloc] into your overrided dealloc mathod... | |||||||||||
|
The As it is no longer needed, it cleans itself up by sending a | |||
You're never supposed to call dealloc explicitly (unless it's [super dealloc] within the dealloc method, but that's the only exception). Objective-C handles memory management via reference counting, so you're simply supposed to match your allocs/retains with releases/autoreleases and let the object deconstruct itself. |
[self dealloc]
inside the-dealloc
definition, then it will result in a recursion. Are you sure the code is correct?– codelogic Feb 18 '09 at 0:36