It's not unheard-of, but it is somewhat uncommon. The main way I've seen it used (and used it myself) is when you're dealing with some sort of semi-synchronous object (by semi-synchronous I mean that it does not block the main thread, but it also does not execute on a background thread; an NSURLConnection
would fit this bill). For example, I wrote a subclass of NSWindowController
that was specifically for displaying a window as a sheet and for invoking some certain delegate callbacks. Basically, you'd alloc
/init
a new sheet controller and invoke beginSheetForWindow:
. This would run the sheet semi-synchronously, and then invoke an appropriate callback when the sheet was dismissed.
Since the invoking object doesn't necessarily "own" the sheet (think of it as a Mac version of a modal view controller on iOS), the sheet controller does [self retain]
immediately before showing the sheet, and [self release]
immediately after cleaning up and invoking callbacks. The purpose behind this was to ensure that the controller object would stick around until the sheet was done. (The sheet, IIRC, was retained by the runloop, but I also needed the controller to stick around)
Like I said, it's very rare to come across a situation where you would want to [self retain]
, but it's not impossible. However, as a general rule of thumb, if you think that you need to [self retain]
, you may want to think again.