iphone - when is the dealloc method called? -
when dealloc method called? i've found (in lot of examples) of ns variables released in method it's instantiated in, when synthesizing component place release in dealloc method.
the apple reference document states subsequent messages receiver may generate error indicating message sent deallocated object (provided deallocated memory hasn’t been reused yet).
you never send dealloc message directly. instead, object’s dealloc method invoked indirectly through release nsobject protocol method (if release message results in receiver's retain count becoming 0). see memory management programming guide more details on use of these methods.
subclasses must implement own versions of dealloc allow release of additional memory consumed object—such dynamically allocated storage data or object instance variables owned deallocated object. after performing class-specific deallocation, subclass method should incorporate superclass versions of dealloc through message super:
important: note when application terminates, objects may not sent dealloc message since process’s memory automatically cleared on exit—it more efficient allow operating system clean resources invoke memory management methods. , other reasons, should not manage scarce resources in dealloc
another question iphone - when dealloc viewcontroller called?
Comments
Post a Comment