NSAutoreleasePool: how does it really work?
NSAutoreleasePool: how does it really work?
- Subject: NSAutoreleasePool: how does it really work?
- From: Lorenzo Puleo <email@hidden>
- Date: Tue, 18 Mar 2003 10:33:19 +0100
I don't understand yet how does NSAutoreleasePool really work.
At the end of the following loop, the "top" command tells me that the Rsize
of my application doesn't decrease anymore. Instead I expect that it should
return to the initial value because I remove all the objects from the
xArray. I get lack of memory all the time. I know that "addObject" retains
the object just added, but, how to free up the memory at the end?
===============================
- (void)MyLoop
{
int i;
xArray = [NSMutableArray arrayWithCapacity:0];
for(i = 0; i < 500000; i++){
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init];
NSString *sourceItem = [[NSString alloc]
initWithFormat:@"Item number %d", i];
[sourceItem autorelease];
[xArray addObject:sourceItem];
[myPool release];
}
[xArray removeAllObjects];
}
===============================
If I use only:
===============================
- (void)MyLoop
{
int i;
xArray = [NSMutableArray arrayWithCapacity:0];
for(i = 0; i < 500000; i++){
[xArray addObject:@"abc"];
}
[xArray removeAllObjects];
}
===============================
it works well: at the end of the loop, the Rsize returns to the initial
value.
Where can I learn more about NSAutoreleasePool? I already read the
documentation, but it seems to be not enough. And what did I do wrong?
Best Regards
--
Lorenzo Puleo
email: email@hidden
_______________________________________________
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.