Re: Size limit of NSData or NSFileHandle?
Re: Size limit of NSData or NSFileHandle?
- Subject: Re: Size limit of NSData or NSFileHandle?
- From: Greg Herlihy <email@hidden>
- Date: Mon, 10 Apr 2006 10:14:27 -0700
- Thread-topic: Size limit of NSData or NSFileHandle?
The autorelease pool holding the NSData should still be released upon every
iteration of the loop. The program will not be able to complete ten
iterations without having released the pool, because there is almost
certainly not enough contiguous virtual address space available to
accommodate ten 268 MB allocations all at the same time.
And while releasing the pool more frequently than every tenth iteration may
avoid complete memory exhaustion, the mere accumulation of such large blocks
of memory can easily cause the hard disk to thrash and the system to come to
a complete crawl as these oversized blocks are continuously being paged to
and from the disk.
For these reasons, I would also reinstate the warning about the consequences
of not releasing the NSData objects in a timely manner. The warning should
also be rewritten, since the one I wrote did not turn out to be very
effective :).
Greg
On 4/10/06 7:47 AM, "glenn andreas" <email@hidden> wrote:
>
> 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
_______________________________________________
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