iPhone memory management tips

5 views
Skip to first unread message

offwhite

unread,
Nov 3, 2009, 11:17:59 AM11/3/09
to Midwest iPhone SDK Developers
I have been learning a lot about dealing with memory leaks the last
week. I have spent a lot of time in the Leaks tool experimenting with
different ways of working with objects and properties. I have learned
that it is not as intuitive as I would like, so testing for leaks
early and often will really help prevent leaks later.

One tip I heard from the Mobile Orchard Podcast is to place the
@synthesize declarations at the top along with the dealloc method and
with a ViewController class you should also place the viewDidUnload
method near the top as well. This way it is easier to see all
resources as they are created and released in one place.

The project I used to learn to better use Leaks is TextDownloader
which is a couple of classes that you can use to download text with a
helper class to use TouchJSON to convert JSON text into an
NSDictionary with JSONDownloader. You can see the classes here.

http://code.google.com/p/mwiphonesdk/source/browse/trunk/Beginners/TextDownloader/Classes/Downloader/

If you look at the history for this folder you can see the changes I
made to deal with memory leaks.

And you can see what to do with viewDidUnload here.

http://code.google.com/p/mwiphonesdk/source/browse/trunk/Beginners/TextDownloader/Classes/TextDownloaderViewController.m

The viewDidUnload method is important when you are creating views and
subviews and need to release these resources.

This TextDownloader code can be copied into any project along with the
TouchJSON code if you need to consume JSON data. Feel free to use it.
Reply all
Reply to author
Forward
0 new messages