Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objects Held Until App End: No Dealloc is okay?

I do not clean up singleton objects that live the life of the application in the dealloc. Is there any reason I should?

- (void) dealloc
{
    // never deallocs
    [super dealloc];
}

I'm kind of assuming that the iOS has me sufficiently walled off to clean all of my app's memory up when it ends. Is that right?

like image 410
Dan Rosenstark Avatar asked Jan 21 '23 11:01

Dan Rosenstark


1 Answers

Yes, when your app is terminated, your app's virtual memory address space will be completely wiped/freed. You can fill out -dealloc if you want, but it will never get called, so the only advantage to doing so is that if you decide to make your object a non-singleton down the track, you've got the dealloc method there already.

One thing to keep in mind is that any singleton (which will exist for the entire life of your app) that has any kind of cache that could reach a large size should register for the UIApplicationDidReceiveMemoryWarningNotification, and reduce or flush the cache as appropriate when a memory warning occurs.

like image 51
Nick Forge Avatar answered Jan 31 '23 06:01

Nick Forge