Difference between release and dealloc in objective-c
转载自: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
|
||||
4 Answers
25
|
Never call If you're going to program Cocoa, you need to read the Memory 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. |
||||||
|
3
|
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... |
||||||||||
|
2
|
The
As it is no longer needed, it cleans itself up by sending a |
||
1
|
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