Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should -dealloc do anything other than release memory?

I inherited an iPhone app at work and I'm new to Objective-C so I don't have my bearings just yet. I encountered code similar to this:

- (void) dealloc {
    [[StaticObject sharedObject] showSomeDialog];

    [super dealloc];
}

I know this is frowned upon in other languages. My spider sense is going crazy looking at that code.

Is this a common Objective-C idiom? Or do I have a crappy codebase to fix?

like image 686
ageektrapped Avatar asked Jul 23 '10 13:07

ageektrapped


1 Answers

You should not put UI code in a -dealloc. General rule of thumb, only use -dealloc to clean up what you've done: release objects, remove observers, etc.

Consider what would happen if this object lived on a thread other than the main thread... now you'd have UI code running on the non-main thread, which is a bad thing.

like image 88
Darryl H. Thomas Avatar answered Oct 05 '22 23:10

Darryl H. Thomas