• 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: Size limit of NSData or NSFileHandle?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Size limit of NSData or NSFileHandle?


  • Subject: Re: Size limit of NSData or NSFileHandle?
  • From: glenn andreas <email@hidden>
  • Date: Mon, 10 Apr 2006 09:47:21 -0500


On Apr 10, 2006, at 9:33 AM, Ondra Cada wrote:

availableData happens to return an autorelease object (just like more or less anything but for alloc/init, new, and mutable/copy). Thus, the proper pattern is (something like)

    for (;;) {
	NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
        NSData *data=[fh availableData];
        if (![data length]) break;
	...
        [pool release];
    }

Depending on the task it might be better to release the pool not each time, but every N times, yadda yadda yadda :)

This will result in a leak as well, since when the break is hit, neither the pool, nor anything in it, will be released. Instead:


NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
for (unsigned i=0;;i++) {
        NSData *data=[fh availableData];
        if (![data length]) break;
	...
	if (i % 10 == 9) { // release every 10 times through
		[pool release];
		pool = [[NSAutoreleasePool alloc] init];
	}
}
[pool release];

(You can, of course, release every time through, or something other than 10)



Glenn Andreas                      email@hidden
 <http://www.gandreas.com/> wicked fun!
quadrium | build, mutate, evolve | images, textures, backgrounds, art

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Size limit of NSData or NSFileHandle?
      • From: Greg Herlihy <email@hidden>
    • Re: Size limit of NSData or NSFileHandle?
      • From: Ondra Cada <email@hidden>
References: 
 >Re: Size limit of NSData or NSFileHandle? (From: Greg Herlihy <email@hidden>)
 >Re: Size limit of NSData or NSFileHandle? (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Size limit of NSData or NSFileHandle?
  • Next by Date: Re: dynamic glyph/character advancement
  • Previous by thread: Re: Size limit of NSData or NSFileHandle?
  • Next by thread: Re: Size limit of NSData or NSFileHandle?
  • Index(es):
    • Date
    • Thread