Reducing peak memory footprint
In general, it is considered best practice to avoid generating autoreleased objects.
[Most of this paragraph amended from this question.] Since you typically(1) don't have direct control over their lifetime, autoreleased objects can persist for a comparatively long time and unnecessarily increase the memory footprint of your application. Whilst on the desktop this may be of little consequence, on more constrained platforms this can be a significant issue. On all platforms, therefore, and especially on more constrained platforms, where possible you are strongly discouraged from using methods that would lead to autoreleased objects and instead encouraged to use the alloc/init pattern.
I would suggest replacing this:
theData = [NSData dataWithContentsOfFile:inFile];
with:
theData = [[NSData alloc] initWithContentsOfFile:inFile];
then at the end of the method add:
[theData release];
This means that theData
will be deallocated before the method exits.
You should end up with:
- (void)readVenueArchiveFile:(NSString *)inFile key:(NSString *)inKey
{
NSMutableData *theData;
NSKeyedUnarchiver *decoder;
theData = [[NSData alloc] initWithContentsOfFile:inFile];
decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
ListClassName *decodedList = [decoder decodeObjectForKey:inKey];
self.venueIOList = decodedList;
[decoder finishDecoding];
[decoder release];
[theData release];
}
This makes the memory management semantics clear, and reclaims memory as quickly as possible.
(1) You can take control by using your own local autorelease pools. For more on this, see Apple's Memory Management Programming Guide.