Re: NSAutoreleasePool: how does it really work?
Re: NSAutoreleasePool: how does it really work?
- Subject: Re: NSAutoreleasePool: how does it really work?
- From: petite_abeille <email@hidden>
- Date: Tue, 18 Mar 2003 12:43:08 +0100
On Tuesday, Mar 18, 2003, at 12:20 Europe/Zurich, Lorenzo Puleo wrote:
- (IBAction)MyLoop2:(id)sender
{
int i;
xArray = [NSMutableArray arrayWithCapacity:0];
for(i = 0; i < 500000; i++){
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc]
init];
[xArray addObject:[NSString stringWithFormat:@"Do leak, step
%d",
i]];
[myPool release];
}
[xArray removeAllObjects];
}
Any idea?
Your array is retaining your strings. The pool allocation/deallocation
inside the loop is frivolous.
If for some reasons you want to micromanage your memory pool, try:
NSAutoreleasePool* aPool = [[NSAutoreleasePool alloc] init];
int count = 500000;
int index = 0;
NSMutableArray* anArray = [NSMutableArray arrayWithCapacity: count];
for ( index = 0; index < count; index++ )
{
[anArray addObject:[NSString stringWithFormat: @"Don't leak, step
%d", index]];
}
[aPool release];
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.