Re: Guidance for learner
Re: Guidance for learner
- Subject: Re: Guidance for learner
- From: Ricky Sharp <email@hidden>
- Date: Tue, 26 Jun 2007 18:05:34 -0500
On Jun 26, 2007, at 5:31 PM, Alan Smith wrote:
The reason I didn't use +[NSData dataWithContentsOfFile:] is because
the returned object is autoreleased and won't be released as fast as
if you release it specifically when done with it. To perfect the above
a little more you could do it lie so:
for (i = 0; i < 7; i++)
{
NSString *filePath = [[NSString alloc] initWithFormat:
@"%@/5a_d.w6s", appDirectory, i];
NSData *data = [[NSData alloc] initWithContentsOfFile: filePath];
files addObject: data];
[filePath release];
[data release];
}
There's no reason to do this unless you'll be creating large amounts
of objects before returning to the run loop, and you want to keep
memory-usage low.
And, should you need to do so, you can simply add an autorelease pool
that will release itself every n iterations.
The above can therefore be a "one-liner" (although, for readability,
I tend to keep things broken out just a bit more):
for (i = 0; i < 7; ++i)
{
[files addObject:[NSData dataWithContentsOfFile:
[NSString stringWithFormat:@"%@/5a_d.w6s", appDirectory,
i]]];
}
This is easy to modify to drop in autorelease pools should you need
them.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden