> On 20 Mar 2018, at 09:38, Wolfgang Lux <[email protected]> wrote:
> 
> 
>> Am 20.03.2018 um 07:31 schrieb amon <[email protected]>:
> 
>> I did try coding
>> p=[NSAutoreleasePool new]; do something; [p release];
>> and in some cases it seemed to help. In others it did not.
>> I'll be digging deeper tomorrow and I will give the macros
>> you suggested a try.
> 
> Just one word of warning. If you use this code (or the equivalent 
> CREATE_AUTORELEASE_POOL macro), be sure to catch any exception that is raised 
> in the "do something" code and make sure that the pool gets released, i.e., 
> use
>  p = [NSAutoreleasePool new];
>  @try {
>    do something;
>  }
>  @finally {
>    [p release];
>  }
> Otherwise, you'll leak a whole autorelease pool on every exception raised in 
> the do something part.

This is good advice, but only partly true.
If an exception occurs, so that a pool does not get released normally, objects 
autoreleased into that pool will live longer ... until the enclosing pool is 
released.
This is because autorelease pools vonceptually form a hierarchy with each newly 
created pool being conceptually inside the previous one, so if a 'shallower' 
level pool is emptied all the enclosed 'deeper' level pools are also emptied.
So whether objects in a 'deeper' pool are considered leaked or not is rather 
context dependent.


_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to