Re: Does cocoa just leak?
Re: Does cocoa just leak?
- Subject: Re: Does cocoa just leak?
- From: Ali Ozer <email@hidden>
- Date: Mon, 1 Oct 2001 09:56:58 -0700
>
Reimplement the above like this
>
>
for(i=0;i<5000;i++){
>
NSAutoreleasePool *pool;
>
pool = [[NSAutoreleasePool alloc] init];
>
[instance ULR];
>
/* Do lots of other interesting stuff */
>
[pool release];
>
}
If you aren't doing too much work in the loop, the overhead of creating
and tearing down the pool might be relatively significant; in that case
you can improve this with something like (TextEdit's TextFinder.m does
this as well):
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (i = 0; i < whatever; i++) {
// ... do interesting stuff ...
if (i % 100 == 0) {
[pool release];
pool = [[NSAutoreleasePool alloc] init];
}
}
[pool release];
Note that this is safe only if there are no autoreleased objects that
need to survive between invocations of the loop. But this condition is
the same as that for putting the pool flush in everytime through the
loop anyway.
Ali