discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNUstep and valgrind


From: Richard Frith-Macdonald
Subject: Re: GNUstep and valgrind
Date: Tue, 20 Mar 2018 10:30:01 +0000


> On 20 Mar 2018, at 09:38, Wolfgang Lux <wolfgang.lux@gmail.com> wrote:
> 
> 
>> Am 20.03.2018 um 07:31 schrieb amon <amon@vnl.com>:
> 
>> 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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]