• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Guidance for learner
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Guidance for learner (From: "Barry" <email@hidden>)
 >Re: Guidance for learner (From: "Alan Smith" <email@hidden>)
 >Re: Guidance for learner (From: Brian Smith <email@hidden>)
 >Re: Guidance for learner (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: Core Data / Bindings question
  • Next by Date: Re: [OT] Don't draw every 10th sample(!) (Was Re: Best drawing technology for audio waveforms, envelopes, etc.?)
  • Previous by thread: Re: Guidance for learner
  • Next by thread: Re: Guidance for learner
  • Index(es):
    • Date
    • Thread