PDA

View Full Version : Difference Between release and dealloc messages????




priyank.ranka
Oct 10, 2008, 03:07 AM
Hi EveryOne,
I know its basic question that i should know but i don't know. Please help me by giving some brief comments on what exactly is the difference between the dealloc method and release method. I am developing a game in which initially when game was over i used to dealloc all the UIImageView objects and used to transfer the control to main menu and when user clicks start game button it alloc all the UIImageView objects. But during the course of game play, game gets deactivated and error splashes on debugger screen is " EXE_BAD_SIGNAL". But the issue was slove when i replaced dealloc by release message. But i don't know what is the exact difference. I went through memory management guide but still didn't get the answer. PLease help me out.



lawicko
Oct 10, 2008, 03:35 AM
This should help you:
http://www.otierney.net/objective-c.html#memorymanagement

priyank.ranka
Oct 10, 2008, 04:59 AM
Thanx alot.Now all my doubts are clear.

xsmasher
Oct 10, 2008, 08:24 AM
Short answer:
Each object keeps a count of how many times it has been retained. Calling "release" reduces that count by one - it does not necessarily get rid of the object, if someone else has retained it. Dealloc is the real deal - the object will be destroyed.

You should not, as far as I know, ever call dealloc (other than [super dealloc] at the end of your own dealloc method.) It will get called by "release" if no one else is retaining the object (When the count has gone to 0.)