开发者

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 h开发者_JS百科as me sufficiently walled off to clean all of my app's memory up when it ends. Is that right?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜