When deallocing a refrence I've seenreleaseanddeallocbeing used for example
-(void)dealloc
{
[foo release];
[nar dealloc];
[super dealloc];
}
My question is when isreleaseto be used and when isdeallocto be used?
Thanks
本文深入探讨了Objective-C中的release与dealloc方法的使用时机与区别,解释了如何正确地进行内存管理以避免潜在的内存泄露问题。
转载自: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-deallocdefinition, then it will result in a recursion. Are you sure the code is correct?– codelogic Feb 18 '09 at 0:36