views:

435

answers:

1

Hi i want to know the difference between drain, release,dealloc and retain in Objective-C.

+3  A: 
  • retain increase the reference count on an object
  • release decreases the reference on an object
  • drain is used in place of release on ONLY for NSAutoreleasePool objects due to some arcana related to the Objective C garbage collection
  • dealloc is called by the system once the retainCount of an object hits 0. It is where you clean up various things your object has (like a deconstructor or finalizer). You should NEVER call it directly, except for calling [super dealloc] at the end of your dealloc routines.

You really should just read through Apple's memory management documentation.

Louis Gerbarg
thank you so much...
suse
-drain is useful on NSAutoreleasePool so that it functions under GC as well. Namely, it triggers a collection immediately. If we used -release, then under GC, that message would be ignored, and nothing would happen.
kperryua