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 objectrelease
decreases the reference on an objectdrain
is used in place of release on ONLY for NSAutoreleasePool objects due to some arcana related to the Objective C garbage collectiondealloc
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 yourdealloc
routines.
You really should just read through Apple's memory management documentation.
Louis Gerbarg
2009-11-02 08:22:03
thank you so much...
suse
2009-11-02 09:16:59
-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
2009-11-02 15:20:09