Re: NSAutoreleasePool: how does it really work?
Re: NSAutoreleasePool: how does it really work?
- Subject: Re: NSAutoreleasePool: how does it really work?
- From: Lorenzo Puleo <email@hidden>
- Date: Tue, 18 Mar 2003 18:14:00 +0100
Ok Bill, thank you,
but please what can I do now? How should I modify my code in order to use
the memory properly? I am trying all the time, unsuccessfully. The unix
"top" command tells me that Rsize and Free Mem never come back to the
initial values.
Should I still
Best Regards
--
Lorenzo Puleo
email: email@hidden
compact the heap like in Carbon?
Best Regards
--
Lorenzo Puleo
email: email@hidden
>
From: Bill Bumgarner <email@hidden>
>
Date: Tue, 18 Mar 2003 11:55:55 -0500
>
To: email@hidden
>
Cc: Lorenzo Puleo <email@hidden>, Phill Kelley <email@hidden>
>
Subject: Re: NSAutoreleasePool: how does it really work?
>
>
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.