Re: NSAutoreleasePool: how does it really work?
Re: NSAutoreleasePool: how does it really work?
- Subject: Re: NSAutoreleasePool: how does it really work?
- From: Bill Bumgarner <email@hidden>
- Date: Tue, 18 Mar 2003 11:55:55 -0500
On Tuesday, Mar 18, 2003, at 11:39 US/Eastern,
email@hidden wrote:
... analysis deleted ...
- (IBAction)MyLoop:(id)sender
{
int i;
xArray = [NSMutableArray array];
for ( i = 0; i < 500000; i++ )
{
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc]
init];
[xArray addObject:[NSString stringWithFormat: @"Don't leak,
step
%d", i]];
[myPool release];
}
[xArray removeAllObjects];
return;
}
The release pool in the above code doesn't actually do anything (except
slowing down the code)!
The @"..." format string is statically allocated; there should be only
one.
The string instance produced by -stringWithFormat: is autoreleased into
myPool, by you shove it into an array inside of myPool's scope. This
ensures that the string is persisted beyond the call to -release on
myPool.
If you were to remove the allocation of myPool, you will likely see a
reduction in the memory usage because of fewer object creation/deletion
events to potentially fragment the heap.
b.bum
_______________________________________________
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.