Is calling [self release] allowed to control object lifetime?

Viewed 5431

I want to create an object in Objective C but I don't hold a reference to it.

Is it allowed to let the object control its own lifetime by calling [self release]?

In case you're wondering why I need this: I want to create an object that subscribes to some notifications, but after a while the object is no longer needed and should go away.

So, is the following allowed?

- (void) destroyMyself {
   [[NSNotificationCenter defaultCenter] removeObserver:self];

   [self release];
} 
6 Answers
Related