In C++ an object can delete itself, in Objective-C calling Dealloc is not something permitted, also with ARC the class may not even have a dealloc.
In Objective-C would be an equivalent way of an object deleting itself as is sometimes done in C++?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no direct equivalent for “delete this” as Objective-C uses reference counting and the system will delete your object when the number of its references reaches zero. If you want to implement some kind of “one-shot” objects i.e. that do something then delete themselves, then your best bet will be to increment the reference count to self when starting the operation with
[self retain]and decrement it when you end with[self release]. If nobody else holds reference to your object, this later will cause the object to delete itself.