Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Pascal Hausberger
Pascal Hausberger
16,453 Points

Dealloc confusion

Hey Stone Preston Matthew Mascioni Kevin Lozandier ,

When does one have to use the dealloc method?

I have never used the dealloc method so far, but even testing on an actual device never caused any problems.

If I don't deallocate, does that increase the memory size of the app on the iPhone? Or is there any other advantage/function for this method?

Thanks a lot!

Cheers, Pascal

4 Answers

Stone Preston
Stone Preston
42,016 Points

if you are using ARC (which you should be) you dont have to worry about using dealloc. ARC takes care of that for you. However there are some cases (like unsubscribing from notifications using NSNotificationCenter) where you would want to implement the dealloc method yourself and perform some custom cleanup tasks. However thats pretty situational and ive only done that in the case of notifications

Matthew Mascioni
Matthew Mascioni
20,444 Points

Seconding Stone Preston's answer :) The main thing I've used it for is in NSNotifications. All new projects use ARC (Automatic Reference Counting) by default now.

Preston is correct, but there are times you still need to clean up for yourself that isn't necessary directly associated with dealloc, but still incredibly important throughout the app lifecycle.

For example, in extreme cases, - (void)didReceiveMemoryWarning can be your best friend as far as managing memory in your application towards an app that is stable and has a relatively low memory footprint than most apps.